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