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

How do you Transform this Script?

I have created a Script that teleports a Player to the Position (0, 0, 0). I would like the player to have to click it with a ClickDetector. How do I change the Script?

function onTouched(hit)  
	local human = hit.Parent:findFirstChild("Humanoid") 
	if (human ~= nil ) then 
		print("Human touched teleport") 
                        hit.Parent.Torso.CFrame = CFrame.new(0, 0, 0)
	end 
end 

script.Parent.Touched:connect(onTouched)

4 comments

0

Use your keyboard. :)

0

You obviously either have a low class of intelligence, a high level of laziness, or an extraordinarily low amount of need to help.

0

I'm no genius, but I think he was just joking.

0

It is annoying though.

1 answer

✓ Accepted answer

Place this script in the part you want to be clicked for the function to operate.

SCRIPT

local part = script.Parent -- get the part
local clickDetector = Instance.new("ClickDetector", part) -- add a clickdetector to the part

clickDetector.MouseClick:connect(function(player) --connect and call the function
	local human = player.Character:findFirstChild("Humanoid") 
	if human then -- if no humanoid then it wont continue
		print("Teleport was Clicked!")  -- print whatever to see if it works
		player.Character.Torso.CFrame = CFrame.new(0, 0, 0) -- parent of 'human' should hte the character, this will set the cframe of the torso to the position 0,0,0
	else
		print("Didn't work!")
	end
end)

The player is already an argument with the MouseClick event, so in the function, in the parameters you add the argument of the player, in this example it's going to be named 'player'

9 comments

0

It is not working. The Part I am using is called Union.

0

what does the output say?

0

I changed it from Unions to Parts and it still does not work.

0

The output is literally saying nothing.

0

edited the script, try that

0

It still did not work.

0

did it print anything, make sure you're using a regular script, not local

0

Can you just make a Model and PM me the link?

0

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