Roblox - FE部分创作者脚本无法使用

我正在制作一个FE Roblox游戏,我在工具中遇到了一个FE代码问题。 我可以得到帮助吗?

在工具中:

script.Parent.Activated:Connect(function()
game:GetService("ReplicatedStorage"):FindFirstChild('TS'):FireServer(game.Players.LocalPlayer)
end)

在事件脚本中

local eventplace = game:GetService("ReplicatedStorage")
eventplace:FindFirstChild('TS').OnServerEvent:connect(function(player)
local rangeball = Instance.new('Part',workspace)
    local rangemesh = Instance.new("SpecialMesh",rangeball)
    rangemesh.MeshType = Enum.MeshType.Sphere
    rangeball.Size = Vector3.new(7,7,7)
    player.Character.Humanoid.WalkSpeed = 0
    rangeball.Parent = workspace
end)
点赞
用户88888888
用户88888888

你在 ReplicatedStorage 中创建了远程事件 "TS" 吗?

另外还有一件事:

当你使用 :FireServer() 时,玩家/客户端参数会自动传递,所以没有必要写成 :FireServer(game.Players.LocalPlayer),因为远程事件将会接收到两个参数,都是客户端/玩家。

你在工具中使用的脚本是一个 LocalScript。你应该使用非本地脚本(或 Scripts)。

还有一件事就是,当你在本地脚本中使用 game.Players.LocalPlayer 时,黑客可以在本地更改 game.Players 的名称,这将导致你的脚本失效。

为了解决这个问题,你需要使用变量。

在工具脚本中:

local tool = script.Parent;

tool.Activated:connect(function();
    local rangeball = Instance.new("Part", workspace); -- 因为你输入了 ', workspace',所以这个 Part 会自动成为 Workspace 的子对象。如果你输入的是 Instance.new("Part", workspace.idk),则会将这个 Part 的父对象指定为 workspace.idk,如果 workspace.idk 不存在,则会报出一个错误。
    rangeball.Shape = "Sphere"; -- 我们可以直接使用 'Shape' 属性来替换球状网格!
    -- 没有必要写成 'rangeball.Parent = workspace',因为使用 'Instance.new("Part", workspace)' 就可以达到同样的效果,因为 Instance.new 方法需要两个参数(类和父对象)!
    pcall(function() -- 我们使用 'pcall()' 来防止发生错误。
        tool.Parent.Humanoid.WalkSpeed = 0; -- 设置玩家的行走速度。
    end);
end);

有了这段代码,你就可以自由地删除事件脚本了!

如果你要使用事件,一定要确保事件脚本位于 ServerScriptService 中,这样更安全,而且可以正确运行。记住,脚本只会在 ReplicatedFirst、ServerScriptService、Workspace 等位置中运行。

希望我的回答能够帮助到你。

最后,欢迎来到 Stack Overflow!

2018-11-11 03:34:40