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

How to add to a value inside of replicatedstorage?

Asked by 6 years ago

I have a value inside of a folder in ReplicatedStorage. Each value is named after the player and there is nothing wrong with the code of instantiating this value. The only issue I'm having is changing the value.

Here is the code

local fold = game.ReplicatedStorage:WaitForChild("Values")

function tou(hit)
if hit.Parent.Humanoid ~= nil then
    local name = hit.Parent.Name
    wait(.5)
    fold.name.Value =  fold.name.Value + 1
    end
end

script.Parent.Touched:Connect(tou)

The error message is:

20:03:48.182 - Workspace.Part.Script:7: attempt to perform arithmetic on field 'Value' (a nil value)

Any help is appreciated :)

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

The problem is that fold.name is the folder's name. Perhaps you were looking for fold[name].Value instead.

I also encourage you not to use such short and not great variable identifiers.

Also that code will error if there is no Humanoid, use Instance:FindFirstChild() when looking so it doesn't.

And hit's parent's name will be a body part, may want to use game.Players:GetPlayerFromCharacter() if this is player-based.

0
Thank you for this advice i will try it out 4d61736f6e 59 — 6y
0
Can you elaborate a bit more on using Instance:FindFirstChild() 4d61736f6e 59 — 6y
0
For example, hit.Parent:FindFirstChild("Humanoid") Avigant 2374 — 6y
0
Thank you again for the help 4d61736f6e 59 — 6y
View all comments (2 more)
0
No problem, please accept my answer and/or vote on it if helped! :) Avigant 2374 — 6y
0
Why'd the parent be a body part? Isn't a body part touching the part, not a descendant? hiimgoodpack 2009 — 6y
Ad

Answer this question