I am trying to increase a player’s stats when they touch a part. This should be simple, but every solution I have tried results in this exact same error.
Below is the current version of my script that made this error
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(hum)
local stats = player.leaderstats.Wins
if hit and hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
hit.Parent.HumanoidRootPart.Position = Vector3.new(0.06, 1.2, -29.08)
stats.Value = stats.Value + 1
end
end)
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(hum.Parent)
local stats = player.leaderstats.Wins
if hit and hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
hit.Parent.HumanoidRootPart.Position = Vector3.new(0.06, 1.2, -29.08)
stats.Value = stats.Value + 1
end
end)
this?
Attempt to index nil means that player hasn’t been defined yet most likely.