Script can't find the leaderstats from player

script:

local prox = script.Parent

prox.Triggered:Connect(function(plr)
	local stats = plr:WaitForChild("leaderstats")

	local fuel = stats.Fuel.Value
	local orbfuel = game.Workspace.Orb.Orb.Fuel

	orbfuel.Value = orbfuel.Value + fuel.Value
	fuel.Value = 0
end)

(no its not a local script cause i don’t think i need one for one player to lose money when they press E on the part)

the error: Workspace.Press E.ProximityPrompt.Script:9: attempt to index number with ‘Value’

a bit more of explanation:
so orb is what needs to be fueled up to level up to the next level, so the player needs to collect the small orbs to collect the fuel, when the player has fuel they can go up to the orb and Press and Hold E for 2 seconds and however much fuel they have will add the number of the fuel to the orbs fuel and also puting the collected fuel to 0 so that player has to get more. once the orb hits 100 fuel (100/100) then the orb will level up and need double the fuel.

Ok, so you need to change script to;

local prox = script.Parent

local player = game:GetService("Players").LocalPlayer or game.Players.LocalPlayer --Best way to avoid hacks

prox.Triggered:Connect(function(plr)
	local user = player --get player from touching human
wait(0.5)
	local stats = user.leaderstats
	
	local fuel = stats.Fuel.Value
	local orbfuel = game.Workspace.Orb.Orb.Fuel
	
	orbfuel.Value = orbfuel.Value + fuel.Value
	fuel.Value = 0
end)

That should fix it.

there is an error " Workspace.Press E.ProximityPrompt.Script:8: attempt to index nil with ‘leaderstats’"

Is there any other script that relate to it, or just this one script?

just that one script I think is the only one

It’s because you’re never defining player. Try this:

prox.Triggered:Connect(function(plr)
	local user = plr
1 Like
local player = game:GetService("Players").LocalPlayer or game.Players.LocalPlayer

Yeah, LocalPlayer is going to return nil if on a server script as the LocalPlayer property is nil on the server.

You can’t define the player like that if it’s on a server script, remove the player variable & reference the plr parameter provided in the ProximityPrompt.Triggered event instead

local prox = script.Parent

prox.Triggered:Connect(function(plr)
	local stats = plr:WaitForChild("leaderstats")
	
	local fuel = stats.Fuel.Value
	local orbfuel = game.Workspace.Orb.Orb.Fuel
	
	orbfuel.Value = orbfuel.Value + fuel.Value
	fuel.Value = 0
end)

But it works when I do it though, may you explain why it wouldn’t??

wanna join the studio and try to fix it? i can add you to my studio game. if your ok with that

You must be using a LocalScript or calling it from the client, it shouldn’t return anything on the server. If it does, it’s a bug and should be fixed.

Screen Shot 2021-05-19 at 9.18.31 PM

Screen Shot 2021-05-19 at 9.19.25 PM

orbfuel.Value = orbfuel.Value + fuel.Value

Probably because you’re assigning a number value to fuel instead of the instance.

You could either do,

local fuel = stats.Fuel

or

orbfuel.Value = orbfuel.Value + fuel

yea but the orbfuel is for the orb that the player needs to level up when that orb has enough fuel it levels up, But the fuel is the little orbs that give the player the fuel so the player can level the orb up.

orb:

little orb:

Oh gotcha.

So basically, it goes small orb → player’s leaderstat → big orb through the proximity prompt?

If so, try this:

prox.Triggered:Connect(function(plr)
	local stats = plr:WaitForChild("leaderstats")

	local fuel = stats.Fuel
	local orbfuel = game.Workspace.Orb.Orb.Fuel

	orbfuel.Value = orbfuel.Value + fuel.Value
	fuel.Value = 0
end)
1 Like

good news and bad news… good news it works by putting the fuel from player to 0. Bad news is the number on the orb didn’t go up…

the orbs script:

local health = script.Parent.Fuel.Value

local orb = script.Parent

health.Changed:Connect(function()
	script.Parent.BillboardGui.TextLabel.Text = "Fuel"..health.Value.."/100"
end)

if health == 100 then
    orb.BrickColor = BrickColor.new*("Neon orange")
end

local health = script.Parent.Fuel.Value

Change Fuel.Value to Fuel. You’re assigning its value to the variable so it’s going to error.

Of course. I guess I can help.