serverscript服务脚本
game.ReplicatedStorage.AdminEvent.OnServerEvent:Connect(function(plr,action,arg1,arg2)
if action == "Teleport" then
plr.Character.HumanoidRootPart.CFrame = arg1.Character.HumanoidRootPart.CFrame
print(arg1)
print(arg1.Character.HumanoidRootPart.CFrame)
print(plr.Character.HumanoidRootPart.CFrame)
本地 GUI 按钮脚本
function OnClicked()
print("clicked")
local arg1
for index, v in pairs(game.Players:GetDescendants()) do if v:Is(script.Parent.Parent.Parent.TextLabel.TextLabel.Text) then arg1 = v
local action = "Teleport"
local plr = game.Players.LocalPlayer
game.ReplicatedStorage.AdminEvent:FireServer(plr,action,arg1)
end
script.Parent.MouseButton1Down:connect(OnClicked)
end
end
game.ReplicatedStorage.AdminEvent:FireServer(plr, action, arg1)
输出或我尝试打印的内容(如 CFrame)没有错误
不知道为什么我在按“使用谷歌登录”时登录了不同的帐户,但我解决了这个问题
这里的问题是您传递了 3 个参数
plr,action,arg1
并接收了 4 个参数。
如果您收到的参数多于传递的参数,则第一个参数默认为玩家。
另外,我从不建议传递玩家值,因为它可能会被利用。
修复方法如下:
game.ReplicatedStorage.AdminEvent.OnServerEvent:Connect(function(plr,action,arg1)
if action == "Teleport" then
plr.Character.HumanoidRootPart.CFrame = arg1.Character.HumanoidRootPart.CFrame
print(arg1)
print(arg1.Character.HumanoidRootPart.CFrame)
print(plr.Character.HumanoidRootPart.CFrame)
end
end)
function OnClicked(PlayerWhoClicked)
print("clicked")
local arg1
for index, v in pairs(game.Players:GetDescendants()) do
if v:Is(script.Parent.Parent.Parent.TextLabel.TextLabel.Text) then
arg1 = v
local action = "Teleport"
game.ReplicatedStorage.AdminEvent:FireServer(action,arg1)
end
end
end
---I don't know why this was in the loop, but it shouldn't be.
script.Parent.MouseButton1Down:Connect(OnClicked)
之前,您会收到 2 个玩家参数,所以这应该可以修复它,这就是它没有错误的原因。
现在,如果您正在执行管理员命令,则可以使用两个玩家参数,但请确保检查第一个参数是否为管理员并且不要传递它,让参数默认为它。