I am trying to make a script that lets me get 1 strength every time a player touches it however it's giving me the following error Workspace.dumbell.Script:5: attempt to index nil with 'leaderstats'
Here is my script: script.Parent.Touched:Connect(function(hit) local player = hit.Parent:FindFirstChild("Humanoid") local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Strength.Value >= 0 then wait() script.Disabled = true script.Parent.Transparency = 1 script.Parent.CanCollide = false plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value + 1 wait(1) script.Parent.Transparency = 0 script.Parent.CanCollide = true script.Disabled = false
end end)
And here is how I got leaderstats and strength:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local strength = Instance.new("NumberValue")
strength.Name = "Strength"
strength.Parent = leaderstats

1 comment
How hard is it to use the code block lel?