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

How to fix "Gravity is not a valid member of part"?

Asked by
h2wk 0
5 years ago
Edited 5 years ago

Hello, so I am trying to make a system that when you touch a brick, it changes the BodyForce to simulate moon gravity. Here is the script:

local part = script.Parent
debounce = true

local function onTouch(hit)
    if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
        debounce = false
        wait(1)
        local gravity = workspace[hit.Parent.Head.Gravity]
        if gravity then
            gravity.Force = Vector3.new(0, 2000 , 0)
        end
        wait(1)
        debounce = true
    end
end

part.Touched:Connect(onTouch)

The BodyForce is given by another script. This script is a ServerScript and located inside a Part.

This is the script that gives the BodyForce

function changeGravity(Head)
    local gravity = Instance.new("BodyForce")
    gravity.Name = "Gravity"
    gravity.Force = Vector3.new(0,0,0)
    gravity.Parent = Head
end

function onPlayerRespawn(property, player)
    if property == "Character" and player.Character ~= nil then
        changeGravity(player.Character.Head)        
    end
end

function onPlayerEntered(newPlayer)
    while true do
        if newPlayer.Character ~= nil then
            break
        end
        wait(5)
    end
    newPlayer.Changed:connect(function(property)
        onPlayerRespawn(property, newPlayer)
    end)
    changeGravity(newPlayer.Character.Head) 
end

game.Players.ChildAdded:Connect(onPlayerEntered)
0
it means that there is no object or property named 'Gravity" in the part User#23252 26 — 5y
0
I know, but I want to know how to fix. h2wk 0 — 5y
0
Put a BodyForce named Gravity in the part. You haven't given enough information for us to say anything more than that. fredfishy 833 — 5y
0
Now? h2wk 0 — 5y

Answer this question