The "nogravity script works fine, but glitches. I want characters to only have it in a specific building, but sometimes when I walk in I dont get the gravity decrease. So, I wanted to make a "reassurance" that the character had the "nogravity". Here's the script that gives gravity if you have and take it away if you walk back through it.
local enabled = true
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.PrimaryPart:FindFirstChild("BodyForce") and enabled then
hit.Parent.PrimaryPart.BodyForce:Destroy()
enabled = false
wait(2)
enabled = true
return
elseif hit.Parent:FindFirstChild("Humanoid") and enabled then
enabled = false
local bf = Instance.new("BodyForce")
bf.force = Vector3.new(0,2000,0)
bf.Parent = hit.Parent.PrimaryPart
wait(5)
enabled = true
end
end)
My Goal: Make sure the player doesnt have it already, then give it to them, if they already have it, then leave them one they had.
Again, this is the script thats already in a part, but sometimes it glitches.

4 comments
Lol, this may sound super confusing but I tried to simplify it.
Is there an error in the script? What's the glitch? By quickly looking through your script it seems like you should be fine
why would you 'return' it's useless at this kind of script, and what kind of glitch?
There is no error in the output, you are able to walk through the part without getting the gravity decrease, so i wanted to make sure that if the player didnt have it that they would get it, and if they did then to leave them alone.