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'

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

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):

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) 
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