Hello, I made a script based on which if I press the gui button it should spawn the player to the specific brick I want. The script doesn't work. I am trying to make the script basically execute the action: if the player that joined the game is on team celtic to then spawn the player to the brick for celtic which is "Celticspawn". I inserted the script as a local script and made the local script a child to the parent (which is the gui textbutton). But in my script I made its not working. Any help thanks. Code is below:
if Player.Team == game.Teams.Celtic then script.Parent.MouseButton1Click:connect(function() game.Players.localPlayer.character.Torso.CFrame = CFrame.new(workspace.Celticspawn.Position) end) end
You should use a RemoteEvent in this case. Here's how I would do it.
First of all, create a RemoteEvent in ReplicatedStorage called "CelticSpawnRemote"
Here's the client side script in the LocalScript.
script.Parent.MouseButton1Click:connect(function() if Player.Team == game.Teams.Celtic then game:GetService('ReplicatedStorage'):WaitForChild('CelticSpawnRemote'):FireServer() end end)
Here's the script you should use in the script in ServerScriptService
game:GetService('ReplicatedStorage'):WaitForChild('CelticSpawnRemote').OnServerEvent:connect(function(plr)--When the server is fired if plr.Team == game.Teams.Celtic then--If player is on the team repeat wait() until plr.Character--Wait for the character plr.Character.Torso.CFrame = CFrame.new(workspace.Celticspawn.Position)--Teleport them end end)
If you have any questions or issues, please comment back on the answer.