I've made a script and put this code but it wont work what is the error?
local price = 2400
local price = 2400 script.Parent.MouseButton1Click:connect(function(click) local player = game.Players:WaitForChild(click.Name) if player.leaderstats:FindFirstChild("Coins").Value >= price.Value then local char = player.Character char.UpperTorso.Position = Vector3.new(85.64, 10.728, 16.66) local coins = player.leaderstats:FindFirstChild("Coins") coins.Value = coins.Value - 2400 end end)
please help me :( there is no error in output! Im kinda new to scripting
You would need to use a remote event and local script. Your script is editing the value from the clients side, so anything changed from the server side would reset the change. So put a remote event in replicated storage. Here is the local script:
local price = 2400 script.Parent.MouseButton1Click:connect(function(click) local player = game.Players.LocalPlayer if player.leaderstats:FindFirstChild("Coins").Value >= price.Value then game.ReplicatedStorage.RemoteEvent:FireServer() end end)
This server script goes in server script service:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) local char = plr.Character char.UpperTorso.Position = Vector3.new(85.64, 10.728, 16.66) local coins = plr.leaderstats:FindFirstChild("Coins") coins.Value = coins.Value - 2400 end)