Player Joining Team only in Local

I Know what’s the difference between Localscript but script, But in Localscript it works, but in script it won’t work, it’s an gui inside of an tool that turns you into the Team “Demon”, it works and shows only for the Localplayer in localscript but it don’t saves for server and don’t show for other players, is there anyway to i fix it?

–Script–

player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:connect(function()
wait(10)
player.Team = game.Teams.Demon
end)

–end of script–

2 Likes

This is because the LocalPlayer variable can only be declared on the client for you to fix this you would have to implement and use remote events

Here is what you would be technically doing

--LOCAL SCRIPT HERE
player = game.Players.LocalPlayer
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
script.Parent.MouseButton1Down:connect(function()
wait(10)
RemoteEvent:FireServer() -- This will initiate a connection between client and server via  remote
end)

as for your server script you would have to do this!

--SERVER SCRIPT HERE!
local RemoteEvent =  Instance.new("RemoteEvent",game:GetService("ReplicatedStorage")) --Create a RemoteEventObject in the replicated storage 
RemoteEvent.Name = "RemoteEvent"

RemoteEvent.OnServerEvent:Connect(function(Player) --Note that when you fire server the first parameter is the player that fired the remote!
	Player.Team = game.Teams.Demons
end)
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.