Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Team change script not totally working?

Asked by 5 years ago
Edited 5 years ago

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?

1 answer

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

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

0
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! 3dwardIsBack -10 — 5y
0
It is recommended that you use Remote Functions to send all to the server and you get all of team gives. yHasteeD 1819 — 5y
0
what if I create multiple local scripts with different group ids. What do I have to do then with the server script? 3dwardIsBack -10 — 5y
0
Its simple, you can edit for send the groupid, i edit for you yHasteeD 1819 — 5y
View all comments (2 more)
0
Ready, i edited. yHasteeD 1819 — 5y
0
I deleted my post. Forgot to make it server-sided. Good thing someone noticed. All this new FE programming makes me go crazyy! TheWaterFoox 255 — 5y
Ad

Answer this question