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

How to take action when a player clicks the play button?

Asked by 6 years ago
Edited 6 years ago

I have a play button on my ROBLOX game, this is the code so far...

local function OnClick()
 script.Parent.Parent:Remove()
end
script.Parent.MouseButton1Click:connect(OnClick)

and that works, but after they click it, I want to teleport them and refresh their character.

game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(422.054, 830.4, 645.525))
game.Players.PlayerAdded:connect(function(player)
    wait(1)
    player:LoadCharacter()
end)

I'm unsure how to combine the code together, please help.

0
Read my answer on here. https://scriptinghelpers.org/questions/47938/how-do-i-make-a-randomizer-with-different-levels-of-rarity-and-then-teleport-meshparts-using-it#48371. It is not ConvertToCFrame, it is CFrame.new. Treat it like Vector3.new, but instead, CFrame. Also, please don't use deprecated stuff. hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by
Pejorem 164
6 years ago

You can't teleport a Character that doesn't exist so you gotta load in the Character first. And then teleport the Character. The Player is just a "folder", a Player object. The Character is a model associated to the Player as a property of the Player.

print(game.Players.Player1.Character:WaitForChild("HumanoidRootPart").CFrame)
0
o and ye, Remove() is deprecated use Destroy() Pejorem 164 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The thing is that Player is not a valid member of Workspace. If you were to access the Character, you would have to access it from the Local Player

game.Players.PlayerAdded:Connect(function(player)
    local char =  player.Character
    char:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(Vector3.new(422.054,  
   830.4, 645.525))
    wait(1)
    player:LoadCharacter()
end)

If this fixed your problem, please accept my answer, if not, please ask as many questions you want

0
Read my answer on here. https://scriptinghelpers.org/questions/47938/how-do-i-make-a-randomizer-with-different-levels-of-rarity-and-then-teleport-meshparts-using-it#48371. It is not ConvertToCFrame, it is CFrame.new. Treat it like Vector3.new, but instead, CFrame. hiimgoodpack 2009 — 6y

Answer this question