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:
1 | if Player.Team = = game.Teams.Celtic then |
2 | script.Parent.MouseButton 1 Click:connect( function () |
3 | game.Players.localPlayer.character.Torso.CFrame = CFrame.new(workspace.Celticspawn.Position) |
4 | end ) |
5 | 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.
1 | script.Parent.MouseButton 1 Click:connect( function () |
2 | if Player.Team = = game.Teams.Celtic then |
3 | game:GetService( 'ReplicatedStorage' ):WaitForChild( 'CelticSpawnRemote' ):FireServer() |
4 | end |
5 | end ) |
Here's the script you should use in the script in ServerScriptService
1 | game:GetService( 'ReplicatedStorage' ):WaitForChild( 'CelticSpawnRemote' ).OnServerEvent:connect( function (plr) --When the server is fired |
2 | if plr.Team = = game.Teams.Celtic then --If player is on the team |
3 | repeat wait() until plr.Character --Wait for the character |
4 | plr.Character.Torso.CFrame = CFrame.new(workspace.Celticspawn.Position) --Teleport them |
5 | end |
6 | end ) |
If you have any questions or issues, please comment back on the answer.