Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

In game currency for new player points button.?

Asked by
lomo0987 250 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by 10 years ago
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)

Ad
Log in to vote
-1
Answered by
LostPast 253 Moderation Voter
10 years ago

@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)

0
It's messed up sorry LostPast 253 — 10y
0
Their was supposed to be a line space between the print line and the wait line after it. LostPast 253 — 10y

Answer this question