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

Unequipping not working ?

Basically, when drinking is == true don't let the player unequip the tool it has to be drinking == false to let him unequip but sadly gives me error attempt to call a nil value what do i do wrong ?

local Tool = script.Parent
local Humanoid = game.Players.LocalPlayer.Character.Humanoid

drinking = false

function Activated(onActivated)
	if not drinking then
		drinking = true
		script.Parent.Smoker.Smoke.Enabled = true
		wait(5)
		script.Parent.Smoker.Smoke.Enabled = false
		drinking = false
	end
end


function onUnequipped()
	
	if drinking == true then
		Humanoid:EquipTool(Tool)
	else
		if drinking == false then
		return end
	end	
end

drinking = false

script.Parent.Unequipped:connect(onUnequipped)
script.Parent.Activated:connect(onActivated)

1 answer

✓ Accepted answer

This is the fixed script:

local Tool = script.Parent
local Humanoid = game.Players.LocalPlayer.Character.Humanoid

local drinking = false

function onActivated()
    if not drinking then
        drinking = true
        script.Parent.Smoker.Smoke.Enabled = true
        wait(5)
        script.Parent.Smoker.Smoke.Enabled = false
        drinking = false
    end
end


function onUnequipped()
	wait(0)
    if drinking then
        Humanoid:EquipTool(Tool)
	end
end

script.Parent.Unequipped:connect(onUnequipped)
script.Parent.Activated:connect(onActivated)

The problem is that you are trying to connect an event to onActivated, when your function is called Activated. When the game tries to call onActivated, it is a nil value, and therefore that error is thrown. Also note that you cannot set the parent of the tool immediately after Unequipped fires; I found that adding a wait(0) fixes this.

4 comments

0

dang, bro im a dum ass... lol..

0

Don't swear...

0

wow, thanks for -rep

0

you people take this too serious...

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