Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to give someone something if they don't already have it?

Asked by
innhale -2
5 years ago
Edited 5 years ago

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.

0
Lol, this may sound super confusing but I tried to simplify it. innhale -2 — 5y
0
Is there an error in the script? What's the glitch? By quickly looking through your script it seems like you should be fine chomboghai 2044 — 5y
0
why would you 'return' it's useless at this kind of script, and what kind of glitch? User#17685 0 — 5y
0
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. innhale -2 — 5y

Answer this question