我正在尝试这个代码
local player = game.Players.LocalPlayer
script.Parent.MouseClick:Connect(function()
-- Change team color to "Really Blue"
player.TeamColor = BrickColor.new("Really blue")
-- Kill the player
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end)
但由于某种原因,当我按下按钮时,我没有被组队。 我是编码新手,语言是 lua (roblox studio)
我尝试过几次将颜色更改为不同的东西,但结果都是相同的。
您无法在客户端(在 LocalScript 中)更改玩家的团队,因此您需要使用 RemoteEvents 来更改玩家的团队。
首先,将 RemoteEvent 添加到 ReplicatedStorage。
然后,LocalScript 应该看起来像这样:
local rs = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
script.Parent.MouseClick:Connect(function()
rs.Event:FireServer()
end)
现在,对于服务器脚本:
local rs = game:GetSerivce("ReplicatedStorage")
rs.Event.OnServerEvent:Connect(function(plr)
player.TeamColor = BrickColor.new("Really blue")
local character = plr.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end