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

In game currency for new player points button.?

I don't know how to fully set up the new player point system. The script will take Cash from them but it won't give them any player points and the button breaks. So I believe it has to do with the player points. If you could help me that would be nice.

local PointsService = Game:GetService("PointsService")
local ting = 0 

function onTouched(hit)

	if ting == 0 then 
	ting = 1 
	check = hit.Parent:FindFirstChild("Humanoid") 

	if check ~= nil then 

		local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
		local stats = user:findFirstChild("leaderstats") 

		if stats ~= nil then 
			local cash = stats:findFirstChild("Cash") 
			cash.Value  = cash.Value - 20000 
			PointsService:AwardPoints(hit.userId, 1)

			wait(5)
		end

	end

	ting = 0 
	end

end

script.Parent.Touched:connect(onTouched)

2 answers

local PointsService = Game:GetService("PointsService")
local ting = 0 
local Cost = 20000

function onTouched(hit)

	if ting == 0 then 
		ting = 1 
		check = hit.Parent:FindFirstChild("Humanoid") 

		if check then 

			local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
			local stats = user and user:FindFirstChild("leaderstats") or false

			if stats then 
				local cash = stats:FindFirstChild("Cash")
				if cash.Value >= Cost and PointsService:GetAwardablePoints() > 0 then 
					cash.Value = cash.Value - Cost 
					PointsService:AwardPoints(user.userId, 1)

					wait(5)
				end
			end
		end

		ting = 0 
	end

end

script.Parent.Touched:connect(onTouched)

@lomo put an else on line 22 and then make another line right their that says print("Not Enough Cash"). This will make it so they can keep their cash if it is lower then 2000.

Should look like this from line 20 to 25.

cash.Value = cash.Value - Cost

PointsService:AwardPoints(user.userId, 1)

else

print("Not Enough Cash")

wait(5)

2 comments

0

It's messed up sorry

0

Their was supposed to be a line space between the print line and the wait line after it.

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