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

Why is the buy button not working i made?

Hi, Im trying to make a button that gives you a sword when you have enough money and reduces the Money leaderstat afterwards, but it doesnt work it gives the tool, but doesnt reduce the money.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	local cash = player.leaderstats.Money.Value
	if cash >= 50 then
		cash = cash - 50
		game.Lighting.Sword:Clone().Parent = player.Backpack
	end
end)

Hope someone can help me

2 answers

✓ Accepted answer
local function OnClicked ()
	if game.Players.LocalPlayer.leaderstats.Money.Value >= 50 then
	game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - 50
	local Sword = game.Lighting.Sword:Clone()
        Sword.Parent = game.Players.LocalPlayer.Backpack
	else return end
end
script.Parent.MouseButton1Click:Connect(OnClicked)

12 comments

0

this is a "copy" of a script i made it works fine with me it changes the leaderstats in filtering enbaled i put the script inside a local script inside a gui

0

Aye mate, you forgot to remove the ")" on line 7 where end is, remove it. :3

0

thx mate, its hard without roblox auto correct ;)

0

maybe u can help me with the leader board problem i have :3

0

i understand. ;)

0

;) yep

0

Sure.

0

;) u should see the "giving more points than expected" in the home page :3

0

Alrighty

0

ty that worked

0

ur welcome ;)a

0

ur welcome ;)

If this is filtering enabled, I would like to inform you that changing stats on local scripts won't work/replicate. As with cloning the sword, it won't replicate to the servers. If this is filtering enabled, I highly suggest you learn about remote events, make it so that when you click on the button, it fires the server where it can do the checks and cloning on the serverside. If this helped, be sure to accept answer as it gives us both +rep and marks the question answered. Report anything else in the comments. Learn about remote events here. https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

4 comments

0

Thx for the answer i will inform myself about the remoteevents. But my game is not filtering enabled and it still doesnt reduce the leaderstat value.

0

Is this a local script or a server script?

0

local script but i also tried using a normal script and it also gave the tool without reducing the leaderstat

0

can i help out?

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