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)

4 comments

0

it means that there is no object or property named 'Gravity" in the part

0

I know, but I want to know how to fix.

0

Put a BodyForce named Gravity in the part. You haven't given enough information for us to say anything more than that.

0

Now?