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

Why is the buy button not working i made?

Asked by 5 years ago

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

Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
5 years ago
Edited 5 years ago
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)
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 CjayPlyz 643 — 5y
0
Aye mate, you forgot to remove the ")" on line 7 where end is, remove it. :3 IIApexGamerII 76 — 5y
0
thx mate, its hard without roblox auto correct ;) CjayPlyz 643 — 5y
0
maybe u can help me with the leader board problem i have :3 CjayPlyz 643 — 5y
View all comments (8 more)
0
i understand. ;) IIApexGamerII 76 — 5y
0
;) yep CjayPlyz 643 — 5y
0
Sure. IIApexGamerII 76 — 5y
0
;) u should see the "giving more points than expected" in the home page :3 CjayPlyz 643 — 5y
0
Alrighty IIApexGamerII 76 — 5y
0
ty that worked Jabba171 16 — 5y
0
ur welcome ;)a CjayPlyz 643 — 5y
0
ur welcome ;) CjayPlyz 643 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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

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. Jabba171 16 — 5y
0
Is this a local script or a server script? DaWarTekWizard 169 — 5y
0
local script but i also tried using a normal script and it also gave the tool without reducing the leaderstat Jabba171 16 — 5y
0
can i help out? IIApexGamerII 76 — 5y

Answer this question