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

Attempt to call a nil value?

I'm trying to make a shop GUI for a little game I'm making, and it was working fine but then I realized it was just moving a tool to the player backpack rather than cloning it. After I tried to do that it broke and now it just says

"Attempt to connect failed: Passed value is not a function"

Then when I click it, it says

"attempt to call a nil value"

I just want to add that I'm quite new and don't know much about scripting

Script:

player = script.Parent.Parent.Parent.Parent.Parent.Parent
local scriptOn = false
local RS = game:GetService("ReplicatedStorage")
local item = game RS:WaitForChild("Milk")

if game.Players.LocalPlayer.leaderstats.Dollaroos.Value >= 15 then scriptOn = true else scriptOn = false
if scriptOn then
	function Click(mouse)	
	local newMilk = item:Clone()    
	newMilk.Parent = player.Backpack
	newMilk.Parent = player.StarterGear
	game.Players.LocalPlayer.leaderstats.Dollaroos.Value = game.Players.LocalPlayer.leaderstats.Dollaroos.Value - 15
	scriptOn = false
end
end
end

script.Parent.MouseButton1Down:connect(Click)

1 answer

I think you forgot a period between game and replicated storage in line 4! If thats not the case, sorry, I suck at scripting as well.

EDIT: So basically the script should be

player = script.Parent.Parent.Parent.Parent.Parent.Parent
local scriptOn = false
local RS = game:GetService("ReplicatedStorage")
local item = game.RS:WaitForChild("Milk")

if game.Players.LocalPlayer.leaderstats.Dollaroos.Value >= 15 then scriptOn = true else scriptOn = false
if scriptOn then
    function Click(mouse)   
    local newMilk = item:Clone()    
    newMilk.Parent = player.Backpack
    newMilk.Parent = player.StarterGear
    game.Players.LocalPlayer.leaderstats.Dollaroos.Value = game.Players.LocalPlayer.leaderstats.Dollaroos.Value - 15
    scriptOn = false
end
end
end

script.Parent.MouseButton1Down:connect(Click)

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