As the title says, when I touch the cookie it does not give a point. If you're wondering what the purpose of the "HasCookie1" datastore, it is to prevent people from rejoining to pick up the cookie again & again awarding more points.
local DataStoreService = game:GetService("DataStoreService")
local HasCookie1 = DataStoreService:GetDataStore("HasCookie1")
amnt = 1 -- amount of cookie
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
local player = game.Players:GetPlayerFromCharacter(h.Parent)
local playerKey = "id_" .. player.UserId
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Cookies")
if (score~=nil) and DataStoreService:HasCookie1(player.UserId, false) then
score.Value = score.Value + amnt
HasCookie1:SetAsync(playerKey, true)
end
end
end
script.Parent:remove()
end
end
script.Parent.Touched:Connect(onTouched)

2 comments
Please use a code block around code
Why have you defined the player twice? is there a reason?