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

Since destroying tool in character do not count as unequip, how would you code it as if it was?

Tool = script.Parent
local vCharacter
local vPlayer

Tool.Equipped:Connect(function(mouse)
	local vCharacter = Tool.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)
	tagHumanoid(vPlayer)
	Tool.creator.Value.Stats.Strength.Value = Tool.creator.Value.Stats.Strength.Value + 50
end)

function tagHumanoid(player)
	print("Tagged")
	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = script.Parent
end

Tool.Unequipped:Connect(function()
	Tool.creator.Value.Stats.Strength.Value = Tool.creator.Value.Stats.Strength.Value - 50
	Tool.creator:Destroy()
end)

That should be my code on equip and unequip, however my unequip script involves destroying the weapon in the player character so it doesn't count as unequipped and the unequip function doesn't connect

3 comments

0

got it, all you have to do is transfer the weapon in character to backpack before destroying it. THANKS :D

0

You could add a wait like wait(0.1) in the unequipped function

0

You could add a wait like wait(0.1) in the unequipped function

1 answer

✓ Accepted answer

Soemthing like GetPropertyChangedSignal:-

script.Parent.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
	-- tool changed parent
end)

Or even using AncestryChanged

script.Parent..ParentAncestryChanged:Connect(function(ins, par)
	if script.Parent == ins then
		-- tool changed parent
	end
end)

But make sure that it will not fire if Unequipped has ran.

Hope this helps.

1 comment

0

Wow, this is really helpful even after I've solved the problem. I can think of many ways to use this since I always wondered what event to use on parent change and the sort xD

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