Hello everyone! I am creating a simulator game, and there's an area where you "sell" your parts collected for in-game currency! And where if you do not have enough, it clones a GUI to player GUI inside the script, and tweens it to you!
Now, EVERYTHING in this script functions, but, it creates multiple of the GUI if you don't have enough, and does the math function:
player.leaderstats.Collected.Value / 2 + player.leaderstats.BrickBux.Value
more than one time!
I'd like to know how to make this While Loop only execute ONCE, and only be reusable after a specific amount of time! I've tried using the wait() functions in order to make this function, but it doesn't seem to work! My full script (ServerScript)will be listed below my end!
Any and ALL help is appreciated! Thank you, ~BryanFehr
while true do
local debounce = false
wait(10)
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player and debounce == false then
debounce = true
if player.leaderstats.Collected.Value >1 then
player.leaderstats.BrickBux.Value = player.leaderstats.Collected.Value / 2 + player.leaderstats.BrickBux.Value
wait(5)
player.leaderstats.Collected.Value = 0
else
local cloneui = script.notenoughparts:Clone()
cloneui.Parent = player.PlayerGui
cloneui.Frame:TweenPosition(UDim2.new(0.3, 0,0.3, 0))
if cloneui.Parent == player.PlayerGui then
end
wait(5)
debounce = false
end
end
end)
end

3 comments
Worked excellent, thank you for your help!
Also another good prctice is to clone guis locally since server should not know about or touch user interface
I would have gone more in depth on those sort of better practices but honestly staying up all night has me beat..