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

how would you make a tool teleport you when you equip it?

Asked by
quinzt 201 Moderation Voter
4 years ago

ive tried to do that by doing this (dont laugh at me I dont know what im doing)

script.Parent.Equipped:Connect(function(plr)
local tp = plr.Parent:FindFirstChild("Humanoid")
if tp then
    local tp1 = plr.Parent:FindFirstChild("HumanoidRootPart")
    if tp1 then
        tp1.CFrame = Vector3.new(27949.941, 52.029, -708.888)
    end
end
end)

script.Parent.Unequipped:Connect(function()
-- will basically be the opposite of above
end)

I know that when you want something to happen when you touch a part, you would do something similar to what I did above. (I basically used pre-existing knowledge to try and figure this one out which doesn't seem to work) anyway, in the dev console it says "attempt to index nil with FindFirstChild" which leads to believe I've done something wrong with the parameters. How would I fix this

1
plr.parent.... you aren't gonna find a humanoid there, that parent is Players aprilsfooled 29 — 4y
0
Are you trying to Move the tool puropusly ?, or are you trying to equip it from an outside souce? ProAimBoi 20 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Server Script

script.Parent.Equipped:Connect(function()

    local Character = script.Parent.Parent
    local HRP = Character.HumanoidRootPart

    HRP.CFrame = CFrame.new(Vector3.new(27949.941, 52.029, -708.888))
end)

You could also add a debounce if you don't want the player to spam it.

0
thanks i didnt think it wuld be that simple quinzt 201 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
local tool = script.Parent

tool.Equipped:Connect(function()

-- teleport code here

end)

Maybe reparent the tool after teleporting or consider using activated to prevent it trying to teleport u again while still equipped.

Log in to vote
0
Answered by 4 years ago

Hello, quinzt! The problem is the Equipped event gets a parameter of the player's mouse, not the actual player itself. Instead, use a LocalScript with LocalPlayer. This would still work even with FE. Try this:

local player = game:GetService("Players").LocalPlayer

script.Parent.Equipped:Connect(function(mouse)
    local character = player.Character or player.CharacterAdded:Wait()

    character:SetPrimaryPartCFrame(CFrame.new(27949.941, 52.029, -708.888))
end)

If this helped you please accept this answer.

Answer this question