**What happened
Hello everyone! So today I got a weird error so I thought it might be my mistake, i tried changing the team of a player from client to server with certain circumstances but couldn’t, so I’m asking you if you might know the reason or the solution to this. To understand my situation more please look at the scripts:
LocalScript
--//Variables
local frame = script.Parent
local player = game.Players.LocalPlayer
local remoteEvent = game.ReplicatedStorage.RemoteEvents.ChangeTeam
local button1 = frame.Army.TextButton
local ID = --Code of the group
button1.MouseButton1Click:Connect(function()
if player:IsInGroup(ID) then
remoteEvent:FireServer(player, "Forest green") --forest green is the color of the team which I have a spawn and actual team for
end
end)
you dont need to include the player object when firing the server
(only when firing clients)
but honestly just fire the server without sending anything, and just make the server check to see what group theyre in, otherwise this wont work as good as you think. (basically never trust the client)
on another note you might want to wait for your assets to load on the client before using them in local scripts. (by using WaitForChild)
--//Variables
local frame = script.Parent
local player = game.Players.LocalPlayer
local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ChangeTeam")
local button1 = frame:WaitForChild("Army"):WaitForChild("TextButton")
button1.MouseButton1Click:Connect(function()
remoteEvent:FireServer()
end)
local remoteEvent = game.ReplicatedStorage.RemoteEvents.ChangeTeam
local ID = 1
remoteEvent.OnServerEvent:Connect(function(player)
if player:IsInGroup(ID) then
player.TeamColor = BrickColor.new("Forest green")
player:LoadCharacter()
end
end)
now you make a variable
player is automatically sent as a varibale
local script
button1.MouseButton1Click:Connect(function()
if player:IsInGroup(ID) then
local colour = BrickColor.new("Forest Green")
remoteEvent:FireServer(color) --forest green is the color of the team which I have a spawn and actual team for
end
end)
–global script
local remoteEvent = game.ReplicatedStorage.RemoteEvents.ChangeTeam
remoteEvent.OnServerEvent:Connect(function(player, color)
player.TeamColor = color
player:LoadCharacter()
end)
ok so, its asking for a Color3 variable so you would want to do
– local script
button1.MouseButton1Click:Connect(function()
if player:IsInGroup(ID) then
local colour = “31, 128, 29” – equals forest green
remoteEvent:FireServer(color) – exclude the player because player is already a tuple.
end
end)
– server script
local remoteEvent = game.ReplicatedStorage.RemoteEvents.ChangeTeam