So i have been scripting a shop and when someone buys something the points go down for a sec and then they go back as the points the user had. This is my script
From starter gui:
local player=script.Parent.Parent local leaderboard=player:WaitForChild("leaderstats") local points=leaderboard:WaitForChild("Points") while wait(3)do points.Value=points.Value+1 end
From Workspace:
game.Players.ChildAdded:connect(function(player) local stats = Instance.new("Model",player) stats.Name="leaderstats" local money = Instance.new("IntValue",stats) money.Name="Points" money.Value=0 end)
Also there is the script from an item from the shop
script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Gravity Coil") local price = 50 local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if stats.Points.Value >= price then stats.Points.Value = stats.Points.Value - price local cloned = item:Clone() local cloned2 = item:Clone() cloned2.Parent = player.Backpack cloned.Parent = player.StarterGear end end)
You need to use a remote event. This is because localscript cannot change an IntValue serverwide, even if the value is located in the player. Add these 2 scripts, and take out ur local script. I am assuming the "Shop" is a Gui Shop. In a script:
local RS = game:GetService("ReplicatedStorage") local function createEvent(eventName) local event = game.ReplicatedStorage:FindFirstChild(eventName) if not event then event = Instance.new("RemoteEvent", game.ReplicatedStorage) event.Name = eventName end return event end local buy= createEvent("BuyGCoil") buy.OnServerEvent:Connect(function(player, price) local points = player:FindFirstChild("leaderstats"):FindFirstChild("Points") local item = RS:WaitForChild("Gravity Coil") points.Value = points.Value - price local clone = item:Clone() local SPclone = item:Clone() clone.Parent = player.Backpack SPclone.Parent = player.StarterGear end
In a localscript in Gui Shop, in a Ui Button:
local price = 50 function onClick() local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if stats.Points.Value >= price then game.ReplicatedStorage:FindFirstChild("BuyGCoil"):FireServer(price) end end script.Parent.Activated:Connect(onClick)
This generally works great, as long as everything is in the right place. If this isn't what you intended, comment on this to let me know. If this works, then mark this as the answer so others don't waste time! Thank you!