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

{FIXED} Why is my script not working?

Asked by 9 years ago

My script is meant to allow players to convert their cash into player points... However I have tried and tried but it never works, could anyone please fix this! This is what I have so far but I can't read the output very well and make sense of it:

points = game:GetService("PointsService")
awardable = points:GetAwardablePoints()
ammount = 10


function onClicked(p)
    if awardable >= ammount then
        if p.leaderstats.Cash.Value >= 50000 then
            p.leaderstats.Cash.Value = p.leaderstats.Cash.Value - 50000
            game:GetService("PointsService"):AwardPoints(p.userId,ammount)
        end
    end
end

script.Parent.MouseButton1Click:connect(onClicked)

THE SCRIPT IS IN A TEXT BUTTON IF YOU NEED TO KNOW

2 answers

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
9 years ago

First of all, make sure the script is a regular script rather than a local script. Local scripts are not allowed to award points. Also, the player is not passed as an argument in mouse click events. Here's how you could do it.

points = game:GetService("PointsService")
awardable = points:GetAwardablePoints()
ammount = 10

local p = script.Parent.Parent.Parent.Parent
--This while loop goes up the object hierarchy until it reaches the player.
while (not p:IsA("Player")) do
p = p.Parent
end

function onClicked()
    if awardable >= ammount then
        if p:FindFirstChild("leaderstats") and p.leaderstats.Cash.Value >= 50000 then
            p.leaderstats.Cash.Value = p.leaderstats.Cash.Value - 50000
            game:GetService("PointsService"):AwardPoints(p.userId,ammount)
        end
    end
end

script.Parent.MouseButton1Click:connect(onClicked)
Ad
Log in to vote
0
Answered by 9 years ago

try spelling amount right

0
I didn't type that up, I used parts of other script to form this one. However thanks for pointing that out I didn't notice! General_Scripter 425 — 9y

Answer this question