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

How do you Transform this Script?

Asked by
SirPaco 66
8 years ago

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)
0
Use your keyboard. :) AwsomeSpongebob 350 — 8y
0
You obviously either have a low class of intelligence, a high level of laziness, or an extraordinarily low amount of need to help. SirPaco 66 — 8y
0
I'm no genius, but I think he was just joking. ScriptGuider 5640 — 8y
0
It is annoying though. SirPaco 66 — 8y

1 answer

Log in to vote
0
Answered by
legosweat 334 Moderation Voter
8 years ago

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'

0
It is not working. The Part I am using is called Union. SirPaco 66 — 8y
0
what does the output say? legosweat 334 — 8y
0
I changed it from Unions to Parts and it still does not work. SirPaco 66 — 8y
0
The output is literally saying nothing. SirPaco 66 — 8y
View all comments (5 more)
0
edited the script, try that legosweat 334 — 8y
0
It still did not work. SirPaco 66 — 8y
0
did it print anything, make sure you're using a regular script, not local legosweat 334 — 8y
0
Can you just make a Model and PM me the link? SirPaco 66 — 8y
0
http://www.roblox.com/item.aspx?id=385482772 -- works, i tested it :) legosweat 334 — 8y
Ad

Answer this question