Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Local gravity isn't affecting the player?

Hello! So I'm making a "gravity touch pad". When the player touches it its supposed to change the gravity for them only. Keep in mind, this is a local script which I have never really worked with. Here's my script:

local button = script.Parent

button.Touched:Connect(function()
	print("hi")
	workspace.Gravity = 50
end)

"hi" is not printed and the gravity does not change (I have checked in both the server and the client's output. It does work with a normal script but the gravity changes for everyone. Does anyone know how I could fix it? I've also heard a bit about custom forces but I'm not sure.

1 comment

0

You are changing the game's gravity so thats why everyone is affected when used with a script. Instead add a BodyForce to the character.

1 answer

✓ Accepted answer

LocalScripts will only work in areas that the client has partial control over (PlayerGui, ReplicatedFirst, Backpack, Character).

Also, you probably shouldn't keep the gravity after the player lands. If that isn't your goal, I can add some example code.

To have the gravity wear off after a few seconds:

button.Touched:Connect(function() 
oG = workspace.Gravity
workspace.Gravity = 50
wait(5)
workspace.Gravity = oG
end)

To make a jump pad (this will work on the server):

Blacklisted = {} -- Array for blacklisted humanoids - this is to prevent overdoing the jumppower.
local button = script.Parent
button.Touched:Connect(function(part) 
	if game:GetService("Players"):GetPlayerFromCharacter(part.Parent) then
		pHum = part.Parent.Humanoid
		if not table.find(Blacklisted,pHum) then
			table.insert(Blacklisted,pHum)
			-- Set a variable telling us what property to use
			local PropertyName = "JumpHeight"
			if pHum.UseJumpPower then
				PropertyName = "JumpPower"
			end
			local oJP = pHum[PropertyName]
			pHum[PropertyName] = oJP*4 -- 4x power
			pHum.Jump = true -- Make the player jump
			local pConnection = nil
			pConnection = pHum.Touched:Connect(function(floor)
				if floor ~= button then
					pHum[PropertyName] = oJP -- Return their jumppower to normal
					local ind = table.find(Blacklisted,pHum) -- Find their humanoid in the Blacklisted table
					table.remove(Blacklisted,ind) -- And remove it
					pConnection:Disconnect() -- Then disconnect
				end
			end)
		end
	end
end)

4 comments

0

Thank you so much for explaining local scripts! I plan to have the gravity wear off a few seconds later.

0

Okay! Sorry for the late reply. In that case, just add a wait() statement to reset the gravity to the original.

0

Sorry, that took a while. (I blame Roblox for confusing me and making me add extra code to check for JumpPower)

0

Sorry, that took a while. (I blame Roblox for confusing me and making me add extra code to check for JumpPower)

This discussion is preserved as it was. New answers, comments, and votes are closed.