I am trying to get a part to check a players leaderstats upon being touched, but for some reason it errors on line 8. Could someone help me figure out why that is?
local Players = game:GetService("Players")
local debounce = false
function onTouch(hit)
if debounce == false then
debounce = true
local plr = game.Players(hit.Parent.Name)
local QuestNum = plr.leaderstats.QuestValue.Value
if QuestNum == 1 then
QuestNum = QuestNum + 1
plr.leaderstats.XP.Value = plr.leaderstats.XP.Value + 20
else
return
end
wait(1)
debounce = false
else
return
end
end
script.Parent.Touched:Connect(onTouch)

2 comments
What's the error?
attempt to call a userdata value, - line 8 function ontouch