Hello ! I made this script but it doesn't work, I have this error which appears but why? My error: attempt to index local 'player' (a nil value) at the line 3 and 15
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
player.Price.Value = 20
print(hit.Parent)
if hit.Parent.Name == "Pickaxe" then
script.Parent.BrickColor = BrickColor.new("Really blue")
local pickaxe = hit.Parent.Parent:WaitForChild("Pickaxe")
pickaxe:WaitForChild("LocalScript").Disabled = false
end
end)
script.Parent.TouchEnded:Connect(function(hit)
print(hit.Parent)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
player.Price.Value = 10
script.Parent.BrickColor = BrickColor.new("Really red")
player.Price.Value = 10
local pickaxe = hit.Parent.Parent:WaitForChild("Pickaxe")
pickaxe:WaitForChild("LocalScript").Disabled = true
end)

3 comments
put print(player) tell me what would come up
AntoninFearless Sometimes I have nil (when I get in and out) and sometimes my player name
You have to run an if conditional statement to check to see if a player touched the part. It is likely detecting the part underneath it.