Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Where's the problem in this point-giving script? Everything works except the part with giving points

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

1 answer

✓ Accepted answer

###You attempted a 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)

###You'll want to get the player from another script to reward them their points.

###On a side note, the parent argument to 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

3 comments

0

I've tried my best but point-giving script still does not work, I've used your script and edited it to work but still I have no idea what am I doing wrong with the point giving script (I've edited script in question)

0

plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + AMOUNT HERE

0

thanks, worked

This discussion is preserved as it was. New answers, comments, and votes are closed.