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

{FIXED} Why is my script not working?

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

✓ Accepted answer

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)

try spelling amount right

1 comment

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!

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