Hi I made this team change script and It doesnt work totally it only places the player into the team but does not do anything else like the spawn is not correct , tools , etc...
script.Parent:WaitForChild("Temple Guard") function EndLoading() game.Players.LocalPlayer.Character["Humanoid"].Health = 0 end script.Parent["Temple Guard"].MouseButton1Click:connect(function() if game.Players.LocalPlayer:IsInGroup(4043351) then game.Players.LocalPlayer.TeamColor = game.Teams["Temple Guard"].TeamColor EndLoading() end end)
Could anyone tell me what the problem is do I have to ad anything?
For this you must use Remote Events for the server to recognize the actions.
You can see here a example:
-- CLIENT script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer() end) -- SERVER game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- (you need to put player,plr anything for get player in first argument.) warn("Fired!") end)
You can see more here: Roblox Wiki - RemoteEvents and RemoteFunctions
Now, create a RemoteEvent and put it on ReplicatedStorage. Create a Script(ServerScript) and put in ServerScriptService. And add this code:
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- Event location function check(color) -- is for check if team of color exists. for i,v in pairs(game:GetService("Teams"):GetChildren()) do if v.TeamColor == color then return true; end end end event.OnServerEvent:Connect(function(player,team_color,id) if player:IsInGroup(id) then if check(team_color) == true then -- if color exists then player.TeamColor = team_color -- set color player.Neutral = false -- You can remove this. Remove Neutral. you can remove this end end end)
Now create in your LocalScript put this code:
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- Event location local player = game:GetService("Players").localPlayer local team = game:GetService("Teams"):WaitForChild("Temple Guard") -- Team location local group_id = 4043351 function EndLoading() repeat wait() until player.Character player.Character.Humanoid.Health = player.Character.Humanoid.Health - player.Character.Humanoid.Health*1000 --[[ Or you can use this: player.Character.Humanoid:TakeDamage(plr.Character.Humanoid.Health+1000) --]] end script.Parent["Temple Guard"].MouseButton1Click:Connect(function() if player:IsInGroup(group_id) then if player.TeamColor ~= team.TeamColor then event:FireServer(team.TeamColor,group_id) -- Send the TeamColor and Group ID for server. EndLoading() end end end)
I made a change if you click to change teams but you click in the same team that you are already. will not do anything.
Hope it helped :D
Need help? tell-me on comments