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

Teleport to spawn button only working in the Roblox editor. But not when published to Roblox?

Asked by
otto045 41
6 years ago

Hello, I made this script that is supposed to teleport the player to spawn when the player clicks on a button. I set it up in StarterGui, then I created a billboardgui, and then a text button. it works when I click on the play in the Roblox editor, but when I publish it to Roblox, it does not work.

countdown = 7



local i = 1
spawn2 = game.Workspace.SpawnLocation
time2 = 7
player = script.Parent.Parent.Parent.Parent
player2 = game.Players.LocalPlayer.Name

function onClicked()
    if script.Parent.Text == ("Teleport to Spawn") then
    for i = countdown,1, -1 do      
        script.Parent.Text = (i)
        wait(1)
    end
    script.Parent.Text = ("Teleport to Spawn")
        player.Character:MoveTo(spawn2.Position)
        local h = game.Workspace:findFirstChild(player2):findFirstChild("ForceField")
    if h~=nil then
        h:remove()
            end
        end
    end
script.Parent.MouseButton1Down:connect(onClicked)

0
Is filteringenabled on? and what type of script are you putting this in? GamingOverlord756 48 — 6y
0
Filtering is not enabled. And I had it in a normal script. I tried putting it in a LocalScript, and I worked thanks for the help :) otto045 41 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

A simpler way to do just that (and this one works):

gui = script.Parent
player = game.Players:GetPlayerFromCharacter(gui)
function onClick()
    if player ~= nil then
    local Destination = game.Workspace.Destination
    player.Torso.CFrame = CFrame.new(Vector3.new(Destination.Position.x, Destination.Position.y + 2, Destination.Position.z))
    wait(1)
end
gui.MouseButton1Down:connect(onClick)

Try that and see how it works.

0
Does not work. Also does not work in the Roblox Editor. But I found the problem, it was that I had it in a normal script, but I needed it in a LocalScript. otto045 41 — 6y
Ad

Answer this question