What do you want to achieve? Keep it simple and clear!
I need a solution/fix to this problem.
What is the issue? Include screenshots / videos if possible!
Basically, when I punch a player in my game I set their toolbar to become completely disabled by firing a client event and disabling the backpack and then re enabling it after a certain amount of time.
So in this video it gets re enabled without waiting the timeAmount: https://gyazo.com/c9046eee69db1ae3fb44b26baabf3e02
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, I have looked for solutions couldnât find any , but I also have noticed that the first time you punch your toolbar gets disabled perfectly and re enables perfectly but the second time and each time on it doesnât work perfectly.
This is the script involved with disabling then re-enabling the backpack:
local coreGui = game:GetService("StarterGui")
script:WaitForChild("DisableBackpack").OnClientEvent:Connect(function(timeAmount)
coreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
wait(timeAmount)
coreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
end)
Sometimes it works perfectly and waits the designated time period but other times it disables then immediately re enables completely ignoring the timeAmount variable If someone has a solution please please let me know. Thank you!
That would suggest to me that timeAmount is nil, meaning wait is just as assuming you want to wait the smallest amount of time possible.
Check your code for firing the client event, and make sure that itâs definitely receiving a number every time. Maybe have it print the value of timeAmount each time it fires so you can check its receiving the right data.
Either that, or its being fired several times, causing the first eventâs re-enable code to run directly after the second one has disabled it. Again, printing to the output will tell you if itâs firing multiple times, and whether you need to add a debounce.
Alrighty, Iâll be sure to do that! Although I know that the timeAmount variable is being given because it works sometimes. What I think is that itâs being fired multiple times which I will check right now, thank you!
Ok, so basically it doesnât get fired multiple times and the timeAmount variable is printed perfectly how it should be. What I think is that the way the system works is when you punch another character and it finds the âBlockâ bool value it destroys it and fires the client and basically my friend and I tested this in game when I perfect blocked him it worked perfectly and his tool bar got disabled then re-enabled and when he starts to perfect block me my tool bar doesnât gets re-enabled too quickly completely ignoring the timeAmount variable.
Also, if this helps I have provided the code below where the client gets fired:
local c = Player.Character
local e = game.Players:GetPlayerFromCharacter(c)
if enemy:FindFirstChild("PerfectBlock") then
enemy:FindFirstChild("PerfectBlock"):Destroy()
c.HumanoidRootPart.Anchored == true
e.PlayerGui.DisableGuis.DisableBackpack:FireClient(e, 2.975)
wait(2.975)
c.HumanoidRootPart.Anchored = false
end
Also, when I was printing the timeAmount variable it stayed consistent even though the wait(timeAmount) wasnât waiting the same amount. Again, what I have noticed is the first time the event is fired on one player it works perfect for that player and if itâs fired on another it doesnât work at all. Or it could just be completely random! I honestly have 0 clue
local coreGui = game:GetService("StarterGui")
script:WaitForChild("DisableBackpack").OnClientEvent:Connect(function(timeAmount)
coreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
wait(timeAmount or 2.975) -- If 'timeamount' is nil it will wait 2.975
coreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
end)
You can use a simple âorâ statement to account for if âtimeAmountâ is nil
Alrighty thanks, I tried it out and it still doesnât work The thing I have been noticing is that the first time the client gets fired it works 100% fine, works perfectly but each time after that it doesnât wait 2.975 or timeAmount. I also printed the timeAmount variable like @cxmeels told me to do and it prints 2.975 itâs so weirdâŚ
Do you think this could be an engine bug? Like it should be waiting the correct time amount and it is when its first fired but all other times after that it isnâtâŚ
All I can suggest really is trying a custom wait implementation:
local function wait(waitTime)
waitTime = type(waitTime) == "number" and waitTime or 1
local RenderStepped = game:GetService("RunService").RenderStepped
local now = os.time()
while os.time() - now < waitTime do
RenderStepped:Wait()
end
end
Honestly, Iâm pretty sure itâs an engine bug Iâve tried 3 different ways of disabling it while waiting the 2.975 seconds and it works the first time and the next it doesnât. I just made it so if you equip a tool while stunned it un-equips so yeah, thank you, and thank you as well @det3rr