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

Simple code doesnt work. Need some quick pointers?

Asked by 5 years ago

Alright so im trying to make a gui thing where you click and it takes you to a parts cframe. simple. but apparently im doing something wrong. heres my code:

local player = game.Players.LocalPlayer
local booth = workspace:WaitForChild('Booth')
local boothTel = booth.BoothTeleport
script.Parent.Activated:Connect(function()
    if player then
    workspace[player.Name].HumanoidRootPart.CFrame = boothTel.CFrame
    player.PlayerGui.BuyBooth.Enabled = false

    end
end)

BuyBooth is a GUI, the booth variable is a model, and boothTel is the teleport part(where people will be teleported to)

0
Is it a LocalScript? User#19524 175 — 5y
0
yes Horrible_Pun 27 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local player = game.Players.LocalPlayer
local booth = workspace:WaitForChild('Booth')
local boothTel = booth.BoothTeleport
script.Parent.Activated:Connect(function()
    if player then -- You don't need to check for the client again, since your activated function pretty much already does that.
    player.Character.HumanoidRootPart.CFrame = boothTel.CFrame -- You forgot to use the proper hierachy (game.Players.LocalPlayer.Character.HumanoidRootPart)
    player.PlayerGui.BuyBooth.Enabled = false

    end
end)
0
sorry for not specifying but the erorr was that BoothTeleport is not a valid member of workspace Horrible_Pun 27 — 5y
Ad
Log in to vote
0
Answered by
piRadians 297 Moderation Voter
5 years ago
Edited 5 years ago

Do not use workspace[player.Name]. Instead, use player.Character since it's more efficient. Using the first method would break the whole script if a player named "Terrain" or any other object in your workspace joined the game.

player.Character.HumanoidRootPart.CFrame = part.CFrame

Answer this question