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
4 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:

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

Log in to vote
0
Answered by
LazokkYT 117
4 years ago
Edited 4 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

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)
Ad

Answer this question