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

Attempt to index nil with Value??


script.Parent.MouseButton1Click:connect(function()
	if script.Parent.Parent.EnterCodesHere.Text == 'Hello' then
		local player = game.Players.LocalPlayer
		local e = player:FindFirstChild("FlexBux")
		e.Value = e.Value + 3000
		script.Parent.Parent.Input.Text = ''
		script.Parent.Text = 'yay you did'
		wait(1)
		script.Parent.Text = 'Submit'
	else
		script.Parent.Parent.Input.Text = ''
		script.Parent.Text = 'i see. false codes.'
		wait(1)
		script.Parent.Text = 'Submit'
	end
	
end)


i dont have really anything to specify. The line with the problem is: Line 5

local e = player:FindFirstChild("FlexBux")

2 comments

0

Isn't line "script.Parent.Parent.Text = "yay you did"

0

No

3 answers

I'm guessing the issue here is that you are changing a value on the client. A better way to work this is to use a remote event that changes the value on the server,

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent')
event:FireServer(e)

you can use a event and send the variable 'e' to change on the server. Please note that on the event you need to have the first argument as 'player', as shown below

local function changeValue(player, e) 
	e.Value = e.Value + 3000
end)

Please accept my answer if it fixes!

1 comment

0

im confused

It's because Player is nil, are you possibly using a ServerScript?

2 comments

0

No it is a local script

0

That's odd

Make sure that your object is in the correct spot. If you are looking for something in game.Players.LocalPlayer.leaderstats and you run

game.Players.LocalPlayer:FindFirstChild()

the object will return as nil.

If the location is correct, you can replace the line with this (I'm assuming your button is inside of a frame inside of a gui):

local e = script.Parent.Parent.Parent.Parent.Player:FindFirstChild("FlexBux")

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