I tried making a hopperbin that takes control of [almost] anything that has a humanoid in it. Works the way it should in studio, but it respawns my character in the actual game, which it shouldn't. Could someone please figure this out?
player = game.Players.LocalPlayer
repeat wait() until player.Character
bin = script.Parent
function assumeControl(character)
local cframe = character.Torso.CFrame
character.Torso.CFrame = CFrame.new(cframe.x, cframe.y+(1/10^3), cframe.x)
--Unanchoring
for _, v in pairs(character:GetChildren()) do
if v:IsA("BasePart") and v.Anchored then v.Anchored = false
elseif v:IsA("Hat") and v.Handle.Anchored then v.Handle.Anchored = false
elseif v:IsA("Tool") then
for _, v2 in pairs(v:GetChildren()) do
if v:IsA("BasePart") and v.Anchored then v.Anchored = false end
end
end
player.Character = character
workspace.CurrentCamera.CameraSubject = character.Humanoid
end
end
function onButton1Down(mouse)
local mt = mouse.Target
if mt and mt.Parent:FindFirstChild("Humanoid") then
assumeControl(mt.Parent)
elseif mt and mt.Parent:IsA("Hat") then
local x = mt
repeat x = x.Parent until x.Parent == workspace
local human = x:FindFirstChild("Humanoid", true)
if human then assumeControl(human.Parent) end
end
end
function onSelected(mouse)
mouse.Button1Down:connect(function()onButton1Down(mouse) end)
end
bin.Selected:connect(onSelected)
