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

Player does not teleport to a specific position?

Asked by
Re_A1 -5
5 years ago

Ok so I wanted to make a gui button teleport to a specific position in my map, and I put the position in the script I made in, (Still a beginner), and.. It's not teleporting me there.

Heres the script: (ps its local script)

local debounce = true local player = script.Parent.Parent.Parent.Parent local target = game.Workspace:WaitForChild("MyPlayerName")

script.Parent.MouseButton1Click:connect(function() if debounce == true then debounce = false player.Character.HumaniodRootPart.CFrame = target.CFrame * CFrame.new(170.26, 402.762, 190.15)

Confused

2 answers

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

In the future please use code blocks, its the blue circle at the top which you can click

there is alot of things wrongs with your code, ill go through them 1 by 1

local debounce = true 
local target = game.Workspace:WaitForChild("MyPlayerName")

script.Parent.MouseButton1Click:connect(function() 

if debounce == true then 

enddebounce = false 
player.Character.HumaniodRootPart.CFrame = target.CFrame * CFrame.new(170.26, 402.762, 190.15)

First, your WaitForChild is actually waiting for a player named "MyPlayerName", but that player definitely isnt you, so its stuck at that line forever and cant go on, if you open the output view you will see the game tells you that infiniteyield possible on WaitForChild, and thats because it is going to be waiting for that imaginary "MyplayerName" forever, so put your Player Name instead like this

local player = script.Parent.Parent.Parent.Parent 
local target = game.Workspace:WaitForChild(player.Name)

Ok so thats fixed, your second problem is where you didnt set the debounce to false correctly

if debounce == true then 

debounce = false --you named the debounce differently than the debounce variable you declared at the beginning of the code.

Third problem, your HumanoidRootPart is named incorrectly, check the spelling

Fourth problem, target is your player object in the workspace, if you use target.CFrame it will throw an error saying CFrame not a member of target, thats because target is talking about the whole player's model in the workspace, use target.HumanoidRootPart.CFrame instead as you want the CFrame of his body parts.

target.HumanoidRootPart.CFrame * CFrame.new(170.26, 402.762, 190.15)

Alright last problem(finally), you didnt end your functions and if statement

script.Parent.MouseButton1Click:Connect(function() 

if debounce == true then 

end--ends the if statement
end)--ends the function

This may be abit long but more problems = longer answer, when you get the code to work, please accept this answer :) it took me awhile to write, and other people can learn from it too

0
This should do, Also you should use :Connect because :connect is deprecated. AswormeDorijan111 531 — 5y
0
ah didnt notice that because i just copied the code, ill edit it aazkao 787 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

Move the torso instead.

0
That would kill the player instantly. Very bad idea. AswormeDorijan111 531 — 5y

Answer this question