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

Why I kept on receiving this error message with the StringValue?

Why I kept receiving this error message? And why the value not changing?

Error Message: 22:25:59.225 - Workspace.Events.Combat System.Movements.Power.current:9: attempt to index nil with 'Value'

local event = game.ReplicatedStorage.GameEvents.Combat.Activate

event.current.OnServerEvent:Connect(function(player)
	local c = player:findFirstChild("current")
	local main = player.PlayerGui.Stuff.Combat.current
	
local char = player.Character
	
c.Value = main.Value
print(c.Value")	

end)

1 answer

First, let's fix the indentation and replace "findFirstChild" with "FindFirstChild"(because the former is deprecated, I think):

local event = game.ReplicatedStorage.GameEvents.Combat.Activate

event.current.OnServerEvent:Connect(function(player)
	local c = player:FindFirstChild("current")
	local main = player.PlayerGui.Stuff.Combat.current
	local char = player.Character

	c.Value = main.Value
	print(c.Value") 
end)

And the only issue I really see is that you did this:

print(c.Value") 

It should be this:

print(c.Value) 

4 comments

0

^^^^^ Always make sure to read over your script before looking to others for help. I'd say 70% of script problems, at least for myself, are purely due to incorrect syntax.

0

Thank you! However, I just found what I did wrong. I forgot player.Character:findFirstChild("current"), when looking for the StringValue <---- with OnServerEvent:Connect(function(player) you get the local player not the model of the player.

0

The script is finally working! ^

0

Ok then mark this as "answered"

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