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

Why is it saying my variable is a nil value?

Here's the output:

11:46:20.944 - Workspace.Buttons.Basic Dropper - FREE.Head.Script:18: attempt to index local 'dropper' (a nil value) 11:46:20.945 - Stack Begin 11:46:20.946 - Script 'Workspace.Buttons.Basic Dropper - FREE.Head.Script', Line 18 11:46:20.947 - Stack End

Here's the script:

function touch(hit)
	Tycoon = script.Parent.Parent.Parent.ID.Value 
	game.Lighting.Purchases:FindFirstChild(Tycoon)
	local x = hit.Parent:FindFirstChild("Humanoid")
	local dropper = Tycoon.BasicDropper

	
	if x ~= nil then
		
	local c =	x.Parent.Name
	local plr = game.Players:FindFirstChild(c)
	if plr ~= nil then
		
		if plr.leaderstats.Money.Value >=00 then
			
			
			plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - 0
			dropper:Clone().Parent = workspace
			script.Parent.Parent:remove()
			
		end
		
	end
	
		
	end
	
end
script.Parent.Touched:connect(touch)

In Lighting, there is a model called 'Purchases'. In Purchases, there is a model called 'one'. The ID value is 'one'. The 'BasicDropper' is where it should be, so what am I doing wrong?

2 comments

0

Use breakpoints, my son! Put a breakpoint right after where you set 'dropper' in studio, and then mouse over all the variables and make sure they're all poitning to the correct things.

0

Thank you, sir! I found out exactly what I did wrong!

1 answer

✓ Accepted answer
function touch(hit)
    Tycoon = script.Parent.Parent.Parent.ID
    game.Lighting.Purchases:FindFirstChild(Tycoon)
    local x = hit.Parent:FindFirstChild("Humanoid")
    local dropper = Tycoon.BasicDropper



BasicDropper is an object not a value right?

1 comment

0

Tycoon could be an ObjectValue is the thing.

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