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

Why is the :Changed event outputting a wierd error code?

:I'm making a script that detects when an Intvalue changes by using the "Changed" event, but whatever I try gives me an error. Here is the error code along with the script I'm using:

Script:

local stats = game.Players.LocalPlayer:WaitForChild('Statistics')
debounce = true

stats.Amount.Changed:connect(function(NewValue)
	if debounce == true then
		debounce = false
		script.Parent.Text = (NewValue..' '..stats.Name.Value)
		wait(0.1)
		debounce = true
	end
end)

Error Code: Players.EnderGamer358.PlayerGui.MainGui.BaseFrame.Amount.ChangeText:7: attempt to concatenate field 'Value' (a nil value) 18:42:20.225 - Stack Begin 18:42:20.228 - Script 'Players.EnderGamer358.PlayerGui.MainGui.BaseFrame.Amount.ChangeText', Line 7 18:42:20.229 - Stack End

:I'm running it through a local script, could this be the problem? Or am I using the event wrong?

1 comment

0

stats.Name will return a string, since it is getting stats Name. If there is another ValueType within the stats folder that is named "Name", use stats["Name"] instead. Instead of getting the child "Name", it's getting the folder's actual Name property.

1 answer

✓ Accepted answer

Try this on line seven:

script.Parent.Text = (NewValue..' '..stats.Amount.Value)

I may be wrong but I think what you are doing is using stats.Name.Value when Value is not a member of the name of stats. If you are trying to accomplish something other than what my code suggests then please comment below and I will do my best to help you. Hope this helps. Have a great day scripting!

3 comments

0

I figured out what the problem was. There was, in fact, a string value inside the folder named "Name", but it may have been trying to get the name of the folder instead. Fixed the issue.

0

No problem.

0

btw when using .Name it will always access the name instead of object instead of the child as far as I know. Try to use a different name in the future

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