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

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

Asked by 4 years ago

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'

01local event = game.ReplicatedStorage.GameEvents.Combat.Activate
02 
03event.current.OnServerEvent:Connect(function(player)
04    local c = player:findFirstChild("current")
05    local main = player.PlayerGui.Stuff.Combat.current
06 
07local char = player.Character
08 
09c.Value = main.Value
10print(c.Value")
11 
12end)

1 answer

Log in to vote
3
Answered by
Rinpix 639 Moderation Voter
4 years ago
Edited 4 years ago

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

01local event = game.ReplicatedStorage.GameEvents.Combat.Activate
02 
03event.current.OnServerEvent:Connect(function(player)
04    local c = player:FindFirstChild("current")
05    local main = player.PlayerGui.Stuff.Combat.current
06    local char = player.Character
07 
08    c.Value = main.Value
09    print(c.Value")
10end)

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

1print(c.Value")

It should be this:

1print(c.Value)
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. NinjaMandalorian 252 — 4y
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. FunimationStudioArt -14 — 4y
0
The script is finally working! ^ FunimationStudioArt -14 — 4y
0
Ok then mark this as "answered" blocky010101 23 — 4y
Ad

Answer this question