local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local playerGui = player:WaitForChild("PlayerGui")
local humanoid = char:WaitForChild("Humanoid")

local dialog = game.ReplicatedStorage.Dialog
local interact = game.ReplicatedStorage.Interact

local price = 5

if player.Data.Coins.Value >= price then
	player.Data.Coins.Value = player.Data.Coins.Value - price -- This is the line that removes 5 coins each time.
	
	blackscreen.Parent = playerGui
	dialog.Continue.Visible = false
	dialog.Cancel.Visible = false
	dialog.NameBox.TextLabel.Text = ""
	dialog.Text.TextLabel.Text = ""
	dialog.Parent = game.ReplicatedStorage
	interact.Parent = game.ReplicatedStorage
	
	for i = 0, 1.02, 0.02 do
		blackscreen.Background.Size = UDim2.new(i, 0, i, 0)
		game:GetService("RunService").Heartbeat:Wait()
	end
	
	wait(2)
	
	for i = 1.02, -0.02, -0.02 do
		blackscreen.Background.Size = UDim2.new(i, 0, i, 0)
		game:GetService("RunService").Heartbeat:Wait()
	end
		
	player.Data.HP.Value = humanoid.MaxHealth
	humanoid.WalkSpeed = 25
	interact.TextLabel.Visible = true
end

What I'm trying to do is, whenever you sleep at an inn, it will take 5 coins and then you will have full HP. The problem is if you do it repeatedly, the price rises by 5 and I don't know why.

6 comments

0

Can you "print(price)" after taking the coins? I want to know if it changes.

0

it prints 5, but the second time i press it it prints twice.. let me see if adding a debounce works.

0

i really dont think it would help but try a debounce?

0

ok now it works

1

tip:u should try and do this on the server becuz this can be easily hacked on the client

0

^^^ Really important, now the cash value only changes for the player. It won't update for the server nor for anyone else, so it basically does not take any money.