For this you must use Remote Events for the server to recognize the actions.
You can see here a example:
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
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")
function check(color)
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
player.TeamColor = team_color
player.Neutral = false
end
end
end)
Now create in your LocalScript put this code:
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local player = game:GetService("Players").localPlayer
local team = game:GetService("Teams"):WaitForChild("Temple Guard")
local group_id = 4043351
function EndLoading()
repeat wait() until player.Character
player.Character.Humanoid.Health = player.Character.Humanoid.Health - player.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)
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
6 comments
Oh I had to use remote functions for that too? I didn't know that I only used for tools yet but thanks a lot!
It is recommended that you use Remote Functions to send all to the server and you get all of team gives.
what if I create multiple local scripts with different group ids. What do I have to do then with the server script?
Its simple, you can edit for send the groupid, i edit for you
Ready, i edited.
I deleted my post. Forgot to make it server-sided. Good thing someone noticed. All this new FE programming makes me go crazyy!