Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

textbutton does not teleport works in studio not in roblox player engine?

SCRIPT

local player = game.Players.LocalPlayer

local Character = player.Character or player.CharacterAdded:Wait()

local Camera = workspace.CurrentCamera

local spawns = workspace:WaitForChild("Map"):FindFirstChild("Spawns")

frame = script.Parent.Parent.Parent

function Click()

Camera.CameraType = Enum.CameraType.Custom

frame.Visible = false

local Spawns = spawns:GetChildren()

local Selected = Spawns[math.random(1,#Spawns)]

Character:MoveTo(Selected.Position + Vector3.new(0, 5, 0))

end

script.Parent.MouseButton1Down:Connect(Click)

why it does not work? in roblox player client launcher but it works in studio. and how can i fix this? LOCAL SCRIPT IN TEXTBUTTON.

1 comment

0

Please use code blocks.

2 answers

Putting 'else' after an 'if statement' might solve your problem for example:

if spawntochoosefrom == 1 then
player.Character.Torso.CFrame = spawns.Spawn1.CFrame
else
if spawntochoosefrom == 2 then
player.Character.Torso.CFrame = spawns.Spawn2.CFrame
else
if spawntochoosefrom == 3 then
player.Character.Torso.CFrame = spawns.Spawn3.CFrame
else
-- and so on!
end
end
end

1 comment

0

does not work.

change this is ur script btw (for any devs out there so u dont downvote me)

   local player = game.Players.LocalPlayer
    
    1.  local Character = player.Character or player.CharacterAdded:Wait()
        
        local Camera = workspace.CurrentCamera
        
        local spawns = workspace.Map.Spawns
        
        frame = script.Parent.Parent.Parent
        
        function Click()
        
        Camera.CameraType = Enum.CameraType.Custom
        
        frame.Visible = false
        
        local Spawns = spawns:GetChildren()
        
        local Selected = Spawns[math.random(#Spawns)]
        
        Character:MoveTo(Selected.Position + Vector3.new(0, 5, 0))
        
        end
        
        script.Parent.MouseButton1Down:Connect(Click)

into

local player = game.Players.LocalPlayer

 local Character = player:WaitForChild("Character")--waits for the character
    
    local Camera = workspace.CurrentCamera
    
    local spawns = workspace.Map.Spawns
    
    frame = script.Parent.Parent.Parent
    
    script.Parent.MouseButton1Click:Connect(function()--connects the function below
    
    Camera.CameraType = Enum.CameraType.Custom
    
    frame.Visible = false
    
    local Spawns = spawns:GetChildren()
    
    local Selected = Spawns[math.random(#Spawns)]
    
    Character.HumanoidRootPart.CFrame = CFrame.new(Selected.Position + Vector3.new(0, 5, 0))--teleports the character to this location
    
    end)

alternatively if this doesnt work, add :WaitForChild("HumanoidRootPart") instead of just .HumanoidRootPart incase they r laggy. that will wait for the humanoidrootpart to load in and then set the cframe to that position

1 comment

0

does not work too..:|

This discussion is preserved as it was. New answers, comments, and votes are closed.