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

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

script.Parent.MouseButton1Click:Connect(function()

local leaderstats = Instance.new("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

        game.ReplicatedStorage.ChangedTeam:FireServer(team)

    end

end)

No errors

2 answers

Log in to vote
3
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

button.MouseButton1Click:Connect(function()
    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
        ChangedTeam:FireServer(team)
    end
end)
0
Thank you so much theking66hayday 841 — 1y
Ad
Log in to vote
0
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