I don't know where is the problem in this script, points aren't awarded. - No errors are shown in the Output (edited script, but still not working)
sp=script.Parent fatalthreshhold=400 safethreshhold=65 lastvelocity=0 while true do wait() local t=sp:FindFirstChild("UpperTorso") if t~=nil then local currentvelocity=(t.Velocity).magnitude local cost=currentvelocity-safethreshhold if cost>0 then local Reward = cost/(fatalthreshhold-safethreshhold)*100 local h=sp:FindFirstChild("Humanoid") local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local stats = thisplr:findFirstChild("leaderstats") if (stats~=nil) then if h then function rewarding(plr) plr.stats.points.Value = plr.stats.points.Value + Reward end end lastvelocity=currentvelocity end end end end end
PlayerAdded
event, but you made it incorrectly. Also, PlayerAdded
fires when a new player joins the game, so if your if statement is true, the game needs to wait for another player to join to give that player the leaderstats. Put this as a script in ServerScriptService
.game:GetService("Players").PlayerAdded:Connect(function(plr) local stats = Instance.new("Folder") -- parent argument is deprecated, assign parent as last property in another line stats.Name = "leaderstats" stats.Parent = plr local points = Instance.new("IntValue") points.Name = "Points" points.Value = 0 end)
Instance.new
is deprecated and is known to slow down performance. :connect()
is also deprecated and has a newer alternative, :Connect()
, which should be used instead. i