In the game I am making, there is a “teleporter” that changes the player’s team and respawns them at the same time. It lets them join the FFA team so they can fight and get weapons. Instead of making another teleporter inside the FFA arena that teamed them back to the default team, I wanted to make a button that did that. I got the button to work no problem, but I want the button to show only when someone is in the FFA team.
I’ve looked all over the devforum but I can’t manage to find anything that works for me. I need this script to check every time someone respawns and to see if they are on the FFA team, and if they are, to give them this button on their screen. To be clear, this code is in a script placed in ServerScriptService. I get no errors in the output either.
local Teams = game:GetService('Teams')
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
if player.Team == Teams.FFA then
local s = game.ServerStorage.LeaveFFA:Clone()
s.Parent = player.PlayerGui
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
1 Like
I put this code in a place and it works just fine. Are you sure the LeaveFFA gui is enabled and its descendants are visible?
Yes, I made it in starterGUI and just copied it over to serverstorage, it works just fine in starterGUI. The screenGUI has a local script in it, as well as a frame which has a textbutton in it, all GUI parts of which have Visible/Enabled check marked.
When I test run, I also see no LeaveFFA gui in my player’s startergui
I see what you mean now-- only works once for whatever reason for me.
What you can do instead is leave the Gui in StarterGui and just make it visible whenever the player spawns on the FFA team. You can accomplish this by just using a LocalScript and using the CharacterAdded event for the LocalPlayer, or you can fire an event to the player from the server and handle it from there.
Let me know if you need any help with that.
You know, that probably would’ve been a lot easier, yeah. I should be able to handle coding that and just tag that as a solution, if not, I’ll reply with the progress I’ve made and see what else I need to do.
Sounds good! Remember to turn ResetOnSpawn off on the ScreenGui, seems to make things easier for me
1 Like
Oh my goodness, THAT is why it worked for you and not me, I forgot the “ResetOnSpawn” property. I’ve had so many problems solved by just messing around with that, you’d think I’d remember to mess with that by now.
Here is the updated script, for anyone seeing this in the future.
local Teams = game:GetService('Teams')
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
if player.Team == Teams.FFA then
local s = game.ServerStorage.LeaveFFA:Clone()
s.Parent = player.PlayerGui
else
for i,v in ipairs(player.PlayerGui:GetDescendants()) do
if v.Name == "LeaveFFA" then
v:Destroy()
end
end
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
1 Like