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

How do I get this handcuff scirpt to work?

Asked by 6 years ago
Edited 6 years ago
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

Log in to vote
0
Answered by 6 years ago

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

Ad
Log in to vote
0
Answered by 6 years ago

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

Log in to vote
0
Answered by
Launderer 343 Moderation Voter
6 years ago
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)

Answer this question