Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui is not teleporting player to brick?

Asked by 5 years ago

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
0
You're using a localscript for a server-side effect. You have to use remote events. manlymouse2002 -12 — 5y
0
Check output for errors so you know what's wrong, if there are none it's either working or not running. For starters you haven't defined Player before using it. If you're new to scripting I suggest you check out some basic tutorials first. gullet 471 — 5y

1 answer

Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
5 years ago

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.

0
Hello popeeyy thank you for attempting to help me. I wrote the localscript as you had it and placed it in the text button so that it is a child and the textbutton is the parent of the local script. Now I placed the other script in serverscriptservice same thing, i inserted the script and copied everything you wrote down and i double check everything and it was good. the script did not work it say Flognaw3210 25 — 5y
0
The Script said Players.Flognaw3210.PlayerGui.ScreemGui.TextButton.LocalScript:2: attempt to index global 'Player' (a nil value) Flognaw3210 25 — 5y
Ad

Answer this question