GUI Not opening when using an equation

Hi! I am attempting to open a gui when a players Y velocity is equal or less then -200. I am using the equation math.abs(200)*-1 to turn 200 into a negative number but this doesn’t seem to working, I know that my code works as when I substitute the equation for a number like 20 then it works perfectly fine. Is there any reason why this may be happening?

Here’s my code:

local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")
local goback = game.Workspace.GoBackPoints:FindFirstChild(char.Name)
local debounce = false
local debounce2 = false
local guilimit = math.abs(200)*-1

while game:GetService("RunService").Heartbeat:Wait() do
	humanoid.StateChanged:Connect(function(oldState, newState) 
		if newState == Enum.HumanoidStateType.Jumping then
			if debounce == false then
				debounce = true
				goback.CFrame = HRP.CFrame
				print("Moved the GoBack part for player "..char.Name)
			end
		end
		wait(2)
		debounce = false
	end)
	
	if char.PrimaryPart.AssemblyLinearVelocity.Y <= guilimit then
		player.PlayerGui.GoBack.GoBack.Visible = true
		print("Enabled help request gui for player "..char.Name)
	end
	
	UIS.InputBegan:Connect(function(key, proccess)
		if key.KeyCode == Enum.KeyCode.F and debounce2 == false then
			debounce2 = true
			print(char.PrimaryPart.AssemblyLinearVelocity.Y)
		end
	end)
	wait(2)
	debounce2 = false
end
  1. I don’t know if that’s what you want, but equal or less of -200 is every number from -200 to minus infinity (e.g -300, -400 etc) so maybe I am wrong about want you want to achieve but I thought I’d put this in in case you got confused

  2. why do you use math.abs(200)* -1 and not -200 or 200 * (-1)? Since 200 is always going to be a positive value I don’t see the reason for math.abs()

What I am trying to do is open a GUI if a player is falling with a velocity of -200 or less so -200 to minus infinity is fine as long as it opens the gui.

I have tried both -200 and 200 * (-1) and neither worked so I used math.abs(200)* -1

The section of this code

	UIS.InputBegan:Connect(function(key, proccess)
		if key.KeyCode == Enum.KeyCode.F and debounce2 == false then
			debounce2 = true
			print(char.PrimaryPart.AssemblyLinearVelocity.Y)
		end
	end)
	wait(2)
	debounce2 = false

was not letting the gui appear for whatever reason. Removing it fixed the problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.