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

How do you fix "attempt to index nil with 'Value"?

Asked by 3 years ago
Edited 3 years ago

Hey, guys!

So I'm trying to make a crop system for my tycoon game, but I am having trouble doing so. I know how to make the crops grow, and I have an idea on how to remove their cash when they purchase the crop, but whenever I run the script, it says "attempt to index nil with 'Value'".

I think that it's important to note that I am using "Zednov's Tycoon Kit" and the money system in the tycoon kit is different than the one that I'm used to, well at least from what the output has told me. I am going to provide the part of the script that the output is bringing me to when it says "attempt to index nil with 'Value'".

I've been trying to fix it on and off for a couple months now and it's getting pretty annoying, so I thought that I'd come here to get some help. Please let me know if there's any way that I could fix this and make it where it takes away the cash when you purchase it in the tycoon kit! Please note for "plr.Value", it doesn't work when I put "plr.Cash.Value".

script.Parent.ClickDetector.MouseClick:Connect(function(click)
    local plr = game.ServerStorage.PlayerMoney:FindFirstChild(click.Parent.Name)
    if plr.Value >= script.Price.Value then -- This is where the issue is occurring.
        plr.Value = plr.Value - 30
-- here is where I put the script that makes the crops grow
        else
        plr.Value = plr.Value - 0
        script.Parent.SurfaceGui.Name = "Need More Money!"
        wait(2)
        script.Parent.SurfaceGui.Name = "Wheat" 
    end
end)

I've also tried "LocalPlayer", but it's not working. It's just saying that I need to "indel nil with Value". I'm not sure what that means and I've tried several ways that didn't work. Does anyone have any idea on how I could fix it? If so, I'd appreciate a response!

0
The error is because of the :FindFirstChild argument, on line 2. What are you trying to accomplish there? JesseSong 3916 — 3y
0
What should I change it to? I'm not the best scripter and I tried making it just "PlayerMoney" and "leaderstats.Cash", but they had the same outcome. The output told me "attempt to index nil with 'Value" and directed me to the "if plr.Value >= script.Price.Value then" line. Do you have any suggestions on how I could fix this? goldenkings11_alt 6 — 3y
0
what are you trying to do in line 2? i can't help if i don't know what you want to achieve JesseSong 3916 — 3y
0
paste the model which you're using here JesseSong 3916 — 3y
View all comments (2 more)
0
I’m sorry for responding late, I just saw this! I am trying to make it where you purchase the soil in the tycoon and then you could click on the soil so 4 buttons appear. The 4 buttons are the crops that you could buy. When you click on the buttons, you lose money and the crop starts growing, which is what’s supposed to happen in the script above. The issue that I’m having is that it’s says goldenkings11_alt 6 — 3y
0
“Attempt to index a nil to ‘Value’” and the output directs me to the line in the script. In the video, he mentioned that the money system is in server storage to prevent hackers from changing the money. I think that’s the issue and the money system only works in the tycoon, like buttons, not a separate model. My overall goal is to remove their cash when they purchase the crop, but it’s not working goldenkings11_alt 6 — 3y

Answer this question