Upon touching the cookie, why does it not give a point?
Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).
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.
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local HasCookie 1 = DataStoreService:GetDataStore( "HasCookie1" ) |
04 | function onTouched(part) |
05 | local h = part.Parent:findFirstChild( "Humanoid" ) |
07 | local thisplr = game.Players:findFirstChild(h.Parent.Name) |
08 | local player = game.Players:GetPlayerFromCharacter(h.Parent) |
09 | local playerKey = "id_" .. player.UserId |
11 | local stats = thisplr:findFirstChild( "leaderstats" ) |
13 | local score = stats:findFirstChild( "Cookies" ) |
14 | if (score~ = nil ) and DataStoreService:HasCookie 1 (player.UserId, false ) then |
15 | score.Value = score.Value + amnt |
16 | HasCookie 1 :SetAsync(playerKey, true ) |
23 | script.Parent.Touched:Connect(onTouched) |