You have a few issues:
- You're never connecting your
CharacterAdded function to any events
- You're attempting to connect
MouseButton1Down to Click, which is only defined inside of a function which is never called. If you're not sure, that means Click is nil when you try to connect it.
- You're trying to set a property of a member of StarterGui. That means that the Player will never notice these changes until they respawn.
CharacterAdded
You need to connect your CharacterAdded function to the Player.CharacterAdded event. That's easy enough once you have the Player in question. Because your script is in a PlayerGui, just keep going up until you reach it.
MouseButton1Down
You need to move your Click function outside of the CharacterAdded function. That's easy enough, given that you don't need the Character in question for your code to work.
StarterGui
Don't change stuff in StarterGui. Never change stuff in the StarterGui. You need to change stuff in the Player.PlayerGui, which is fine for you because you can do it all relative to script or Player - Both of which are available to you from the get-go.
In all, your fixed code should look something like:
local Player = script;
repeat Player = Player.Parent until Player.Parent == game.Players
local Character = Player.Character or Player.CharacterAdded:wait();
if not Player.Respawned.Value then
Player.PlayerGui.ScreenGui.SpawnGui.Visible = true
end;
function Click(mouse)
if game.Workspace.ERDSObj.Marker.Color == Player.TeamColor then
Player.Character.Torso.CFrame = CFrame.new(0,0,0)
Player.PlayerGui.SpawnGui.Visible = false
end
end
script.Parent.MouseButton1Down:connect(Click)
And then in another script, because of how your dodgy code is handling itself, you'll need a script that tells the script whether the Player has respawned.
game.Players.PlayerAdded:connect(function(p)
local i = Instance.new("BoolValue");
i.Name = "Respawned";
i.Value = false;
i.Parent = p;
p.CharacterAdded:wait():WaitForChild("Humanoid").Died:wait();
i.Value = true
end);