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

How do I get this handcuff scirpt to work?

script.Parent.Handle.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end 
local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
if hit.Parent:FindFirstChild("Gun") then  hit.Parent:MoveTo(game.Workspace.Prison.Position) return end 
if player.Backpack:FindFirstChild("Gun") then hit.Parent:MoveTo(game.Workspace.Prison.Position) 
end)

I want the player to teleport (when touched by the handcuffs) to the prison if they have a gun in their backpack. But when the handcuffs touch the player the player bounces back and forth between the handcuffs and the prison.

3 answers

✓ Accepted answer

You're using MoveTo() which is only for Models and the Humanoid for walking. Just get the HumanoidRootPart and change it's CFrame.

MoveTo() is touchy, would recommend setting the models primary part CFrame using model:SetPrimaryPartCFrame(game.Workspace.Prison.CFrame)

script.Parent.Handle.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Gun") then 
hit.Parent.HumanoidRootPart.CFrame=CFrame.new(game.Workspace.Prison.Position) return end
if player.Backpack:FindFirstChild("Gun") then hit.Parent:MoveTo(game.Workspace.Prison.Position)
end)

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