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)
You don't need to create a new folder just to get the leaderstats, you can get it using
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)
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).