Remote Event Firing For No Reason?

Hi, I am trying to make a gui that can delete/add teams. I am almost done with it but I am having a problem with my remote events.

As soon as I join the game, my remote events just fire for no reason

also here is my code:

This is the code inside the Confirm button

local team = script.Parent.Parent.CurrentTeam.Value

game.ReplicatedStorage.DeleteTeam:FireServer(team)

And this is the code inside ServerScriptService

game.ReplicatedStorage.DeleteTeam.OnServerEvent:Connect(function(player, team)

local teamchosen = game.Teams:FindFirstChild(team)

teamchosen:Destroy()

end)

Anyways if you could help me figure out why this is happening that would be great, Thanks!

Because you didn’t put the FireServer in a function or something so script just fires is as soon as script starts to run.

2 Likes

to expand on what @BenMactavsin said; you need to connect the button click to a function like this:

script.Parent.Activated:Connect(function()
    local team = script.Parent.Parent.CurrentTeam.Value
    game.ReplicatedStorage.DeleteTeam:FireServer(team)
end)

Your current code runs when the script starts up, which is when the player joins, so it fires the server and the server deletes the team.

2 Likes

I wish I could give both of you guys the solution lol, thanks to both of you! :slight_smile: