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

Force-Equipt not working?

Asked by 8 years ago

This script was placed inside of the gun, and when I try to run it this error appears: 12:07:19.710 - Something unexpectedly tried to set the parent of Assault Rifle [30] to Player while trying to set the parent of Assault Rifle [30]. Current parent is Backpack. Any Ideas? Here is the full code:

local tool = script.Parent-- Tool
local player = script.Parent.Parent -- Player
player.Character.Humanoid:EquipTool(tool)
tool.CanBeDropped = false
function equipAgain()
    player.Character.Humanoid:EquipTool(tool)
end
tool.Unequipped:connect(equipAgain)

1 answer

Log in to vote
0
Answered by
Mokiros 135
8 years ago

To equip tool you can just move it into character model, because that's how standart tool equipping works. And your script also must wait untill player character loads in order to equip a tool.

local tool = script.Parent
local player = script.Parent.Parent.Parent
repeat wait() until player.Character --Wait until player model loads
tool.Parent = player.Character --Equipping tool
tool.CanBeDropped = false
function equipAgain()
    if tool.Parent == "Backpack" then
            tool.Parent = player.Character
    end
end
tool.Parent.Changed:connect(equipAgain)
0
I dont get the error, but it allows me to put away the tool, any ideas ghosteffectz 115 — 8y
0
I changed it, now it should equip a tool if parent changed to "Backpack" Mokiros 135 — 8y
0
Awesome Thanks! ghosteffectz 115 — 8y
0
If it helped you, please accept the answer ;) Mokiros 135 — 8y
0
It all of the suddent stopped working? ghosteffectz 115 — 8y
Ad

Answer this question