I’m practicing my scripting skills with remote events and creating a touch event that triggers a shop to appear. The problem is when I don’t have enough money to buy the item in the shop, I can’t make the shop gui disappear once I try to buy it with the incorrect amount of money. I swapped the gui as parameters and tried using debounce to align or correct the issue. I think the debounce did work but I don’t think that’s the proper way to fix this issue.
Local script(buying local script):
local shopgui = script.Parent.ShopGui
local exitgui = script.Parent.ExitGui
local button = shopgui.Frame.Buy
local value = button.Value
local player = game.Players.LocalPlayer
local money = player.leaderstats.Money
button.MouseButton1Click:Connect(function()
game.ReplicatedStorage.MoneyEvent:FireServer(value.Value, tonumber(money.Value), shopgui, exitgui)
end)
game.ReplicatedStorage.TouchEvent.OnClientEvent:Connect(function()
script.Parent.ShopGui.Enabled = true
end)
leaderstats and events for shop:
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local money = Instance.new("IntValue", folder)
money.Name = "Money"
end)
game.ReplicatedStorage.MoneyEvent.OnServerEvent:Connect(function(player, cost, amount, shop, exit)
print(cost)
print(amount)
print(shop)
if cost > amount then
shop.Enabled = false
exit.Enabled = true
task.wait(2)
exit.Enabled = false
shop.Enabled = true
elseif cost <= amount then
local newamount = amount - cost
player.leaderstats.Money.Value = newamount
end
end)
game.Workspace.Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.TouchEvent:FireClient(player)
end)
1 Like
I don’t think this would work
if cost > amount then
shop.Enabled = false
exit.Enabled = true
task.wait(2)
exit.Enabled = false
shop.Enabled = true
instead do something like this:
player.PlayerGui.ShopGui.Enabled = true
player.PlayerGui.ExitGui.Enabled = true
1 Like
It wouldn’t work because it’s a script from the server, and what I wrote previously were arguments from the local script I sent to the server.
1 Like
Output said: “ShopGui is not a valid member of PlayerGui “Players.Violet_sheer.PlayerGui””
1 Like
yes it can, the server can acess the localplayer stuff aslong as a function gives it the player object
1 Like
my bad i didn’t see the folder

just add the folder in
Oh yeah it works, the problem is when I’m touching the part it appears visible instantly.
1 Like
… don’t just copy and paste, know what the script does (forgot the folder again)
player.PlayerGui.ShopGui.Enabled = false
player.PlayerGui.ExitGui.Enabled = true
task.wait(2)
player.PlayerGui.ExitGui.Enabled = false
player.PlayerGui.ShopGui.Enabled = true
1 Like
well you’re going into the playergui and getting the gui and unenabling it for one and opposite for the other and then in 2 seconds your doing the opposite.
1 Like
if cost > amount then
shop.Enabled = false
exit.Enabled = true
task.wait(2)
exit.Enabled = false
shop.Enabled = true
this is literally from your code
1 Like
That’s true, it is[Character limit]
1 Like
Never mind, the problem is in the local script
game.ReplicatedStorage.TouchEvent.OnClientEvent:Connect(function()
wait(1)
script.Parent.ShopGui.Enabled = true
end)
1 Like
I tried using debounces but it still doesn’t work properly.
1 Like
welp, atleast the first problem is solved.
did you debound the server script or the client? (you should debounce the serverscript)
1 Like
Debouncing isn’t gonna work, I need to like align the seconds and that just doesn’t sound right.
1 Like
yes it is, debounding is extremely common in .touch script due to players moving so much and triggering it every second
db = false
game.Workspace.Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not db then
db = true
game.ReplicatedStorage.TouchEvent:FireClient(player)
wait(1)
db = false
end
end)
1 Like
The problem is once a player has touched it the first time, he/she has already made the enabled = false and enabled = true clash together so that it wouldn’t work.
1 Like
It does work every other time after just not the first time.
1 Like
why does it clash together? you mean when they can’t pay and it closes, but they touch it again?
1 Like

in that case its a game design problem, maybe flash the buy button with “insufficient funds” or something
2 Likes