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

Why does this RemoteEvent script respawn a player but not team them?

Asked by 8 years ago

Can anyone tell me why this RemoteEvent script respawn's the player but doesn't team them? I know I could use game.Players.LocalPlayer.TeamColor = game.Teams.TestTeam.TeamColor or whatever but that doesn't work with FilteringEnabled. Any help appreciated.

Script for when it's fired(In a ServerScript in ServerScriptService):

local Event = game.ReplicatedStorage.ChangeTeam

Event.OnServerEvent:connect(function(Player,Team)
    Player.TeamColor = Team.TeamColor
--  wait(0.30)
    Player:LoadCharacter()
end)

Script to fire it(In a LocalScript):

local Event = game.ReplicatedStorage.ChangeTeam

script.Parent.MouseButton1Click:connect(function()
    Event:FireServer(game.Players.LocalPlayer,game.Teams.TestTeam)
end)
2
Take out the first argument in the Localscript. When you are firing a server, it is already passing the player as an argument. See if that works Necrorave 560 — 8y

1 answer

Log in to vote
3
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

It's because with RemoteEvents and RemoteFunctions, the Server automatically gather's the client who fired or invoked the object.


Solution

All you have to do is remove the first argument you placed in the FireServer function one line three of the LocalScript.


Final Script

local Event = game.ReplicatedStorage.ChangeTeam

script.Parent.MouseButton1Click:connect(function()
    Event:FireServer(game.Teams.TestTeam)
end)

If you have any questions feel free to ask them in the comments below. And if this answered your question do not forget to hit the Accept Answer button.
0
Thanks. ISellCows 2 — 8y
Ad

Answer this question