0
votes

So what I am trying to create is a TeamChanger, if a button is pressed the LocalScript fires the Server and a Script in ServerScriptService will connect on it, but I have one problem.

I want that the ServerScript to connect only to one function when the LocalScript has fired the Server (Each Join Button for the Teams fire the Same RemoteEvent)

So basically if Button1 will be Pressed the Script will only use Function1

But if Button2 will be pressed the Script will only use Function2 and so on.

Any Ideas?

Update:

All Buttons LocalScript:

TR = game.ReplicatedStorage.TeamChangeRE


function buttonPressed()
    TR:FireServer()
end

script.Parent.MouseButton1Click:Connect(buttonPressed)

Serverscript:

local Team = game:GetService("Teams")
local TRE = game.ReplicatedStorage.TeamChangeRE

function CDTeam(player)
    if player:IsInGroup(7465879) == 1 then
        player.Team = Team["Class-D"]
    end
end


function FPTeam(player)
    if player:IsInGroup(7465879) == 3 then
        player.Team = Team["Foundation Personnel"]
    end
end


TRE.OnServerEvent:Connect(CDTeam)
TRE.OnServerEvent:Connect(FPTeam)

Basically what I am trying to reach is that if a Button has been pressed, only a specific Function in the Script will fire instead of all. (Which causes that the player is getting Teamed Multiple Times)

1
Could you add a code sample with your issue?Kylaaa
Posted the Scripts below.ShahinIX
You should edit your question to include the scripts, not post them as answers.Kylaaa
I have fixed it now.ShahinIX

1 Answers

0
votes

It's not possible for a RemoteEvent to only fire for one connection.

But in your example, why not just combine the functions into one? The player:IsInGroup() function returns a bool, not a number so you can place people in teams based on that.

local Team = game:GetService("Teams")
local TRE = game.ReplicatedStorage.TeamChangeRE

function joinTeam(player)
    if player:IsInGroup(7465879) then
        player.Team = Team["Class-D"]
    else
        player.Team = Team["Foundation Personnel"]
    end
end

TRE.OnServerEvent:Connect(joinTeam)