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

How to add to a value inside of replicatedstorage?

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

✓ Accepted answer

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.

6 comments

0

Thank you for this advice i will try it out

0

Can you elaborate a bit more on using Instance:FindFirstChild()

0

For example, hit.Parent:FindFirstChild("Humanoid")

0

Thank you again for the help

0

No problem, please accept my answer and/or vote on it if helped! :)

0

Why'd the parent be a body part? Isn't a body part touching the part, not a descendant?

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