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

Local script won't remove money or do anything??

Asked by 1 year ago

Hi I am trying to make player pay Money to unlock a certain team. local script in Gui button


local leaderstats ="Folder")

local sp = leaderstats:findFirstChild("Money") 

if sp == nil then return false end 

if (sp.Value >=100) then --Amount of how much the weapon will go for

    sp.Value = sp.Value - 100

        local team = script.Parent.Name




No errors

2 answers

Log in to vote
Answered by 1 year ago

I assume that there's already a Script in ServerScriptService that's creates the leaderstats Folder.

You don't need to create a new folder just to get the leaderstats, you can get it using Player:WaitForChild("leaderstats").

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player: Player = Players.LocalPlayer
local ChangedTeam: RemoteEvent = ReplicatedStorage:WaitForChild("ChangedTeam")

local button = script.Parent

    local leaderstats: Folder = Player:WaitForChild("leaderstats")
    local money: IntValue = leaderstats:WaitForChild("Money")

    if money.Value >=100 then
        money.Value -= 100

        local team: string = button.Name
Thank you so much theking66hayday 841 — 1y
Log in to vote
Answered by 1 year ago
Edited 1 year ago

While your actual issue is due to what the other answer already mentioned – I can tell you that your LocalScript will not deduct any actual money from the user.

This is because of client-server replication. What changes on a client is not replicated to the server, for security purposes, and a LocalScript – as the name says, only executes Locally or in other words, Client-side.

Nonetheless, to solve this issue of client-server replication you can simply try using a Script instead or resort to making a Remote (with proper sanity-checks to avoid exploitation, of course).

Answer this question