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 2 years ago

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

01script.Parent.MouseButton1Click:Connect(function()
02 
03local leaderstats = Instance.new("Folder")
04 
05local sp = leaderstats:findFirstChild("Money")
06 
07if sp == nil then return false end
08 
09if (sp.Value >=100) then --Amount of how much the weapon will go for
10 
11    sp.Value = sp.Value - 100
12 
13        local team = script.Parent.Name
14 
15        game.ReplicatedStorage.ChangedTeam:FireServer(team)
16 
17    end
18 
19end)

No errors

2 answers

Log in to vote
3
Answered by 2 years 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").

01local Players = game:GetService("Players")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03 
04local Player: Player = Players.LocalPlayer
05local ChangedTeam: RemoteEvent = ReplicatedStorage:WaitForChild("ChangedTeam")
06 
07local button = script.Parent
08 
09button.MouseButton1Click:Connect(function()
10    local leaderstats: Folder = Player:WaitForChild("leaderstats")
11    local money: IntValue = leaderstats:WaitForChild("Money")
12 
13    if money.Value >=100 then
14        money.Value -= 100
15 
16        local team: string = button.Name
17        ChangedTeam:FireServer(team)
18    end
19end)
0
Thank you so much theking66hayday 841 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years 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