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

Attempt to call a nil value?

Asked by
CL4VIN 9
5 years ago

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:

01player = script.Parent.Parent.Parent.Parent.Parent.Parent
02local scriptOn = false
03local RS = game:GetService("ReplicatedStorage")
04local item = game RS:WaitForChild("Milk")
05 
06if game.Players.LocalPlayer.leaderstats.Dollaroos.Value >= 15 then scriptOn = true else scriptOn = false
07if scriptOn then
08    function Click(mouse)  
09    local newMilk = item:Clone()   
10    newMilk.Parent = player.Backpack
11    newMilk.Parent = player.StarterGear
12    game.Players.LocalPlayer.leaderstats.Dollaroos.Value = game.Players.LocalPlayer.leaderstats.Dollaroos.Value - 15
13    scriptOn = false
14end
15end
16end
17 
18script.Parent.MouseButton1Down:connect(Click)

1 answer

Log in to vote
0
Answered by
LazokkYT 117
5 years ago
Edited 5 years ago

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

01player = script.Parent.Parent.Parent.Parent.Parent.Parent
02local scriptOn = false
03local RS = game:GetService("ReplicatedStorage")
04local item = game.RS:WaitForChild("Milk")
05 
06if game.Players.LocalPlayer.leaderstats.Dollaroos.Value >= 15 then scriptOn = true else scriptOn = false
07if scriptOn then
08    function Click(mouse)  
09    local newMilk = item:Clone()   
10    newMilk.Parent = player.Backpack
11    newMilk.Parent = player.StarterGear
12    game.Players.LocalPlayer.leaderstats.Dollaroos.Value = game.Players.LocalPlayer.leaderstats.Dollaroos.Value - 15
13    scriptOn = false
14end
15end
16end
17 
18script.Parent.MouseButton1Down:connect(Click)
Ad

Answer this question