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

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

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

2 comments

1

plr.parent.... you aren't gonna find a humanoid there, that parent is Players

0

Are you trying to Move the tool puropusly ?, or are you trying to equip it from an outside souce?

3 answers

✓ Accepted answer

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.

1 comment

0

thanks i didnt think it wuld be that simple

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.

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.

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