Script only runs when open

so, I made a part that changes he workspace’s gravity whenever you touch it. But it only works when the script is open. here’s the script:

local part = game.Workspace.LowGravBrick

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		print(game.Workspace.Gravity)
		game.Workspace.Gravity = 55
		print(game.Workspace.Gravity)
	end
end)

this is in a local script because I wanted it to only change the gravity for the person who touched it.

  • is the script inside of workspace? if so it wont run
1 Like

I put the script in workspace and in a ServerScript but it’s not running still

Do you think that this is a bug or a scripting issue?

the script should be inside of starterplayerscripts and/or playergui

doesnt matter which one you pick

1 Like

If you’re running this inside a LocalScript, you could simplify it a LOT more.

local part = workspace.LowGravBrick
local player = game.Players.LocalPlayer

part.Touched:Connect(function(hit)
	if hit.Parent == player.Character then
		print(game.Workspace.Gravity)
		game.Workspace.Gravity = 55
		print(game.Workspace.Gravity)
	end
end)
4 Likes

What do you mean by the script open? is it opened in the tab?

I do mean opened in the tab, sorry for the poor wording.
Also thanks for your help!

Sorry but that worked at first but then it stopped for some reason. I’ll reset my computer and then try again.

Make sure to put the script in either StarterGui, StarterCharacterScripts or StarterPlayerScripts.

1 Like

it works now, thanks for your help, and sorry for going on here without explore other option first.

The problem is the local script. Where are you placing the local script? Local scripts can only work in workspace if it’s inside the player’s character. So to do this, you would need to put it in a server script, when touched, detect the player that touched it, fire a remote event to that specific player and then when the signal is received by the player, locally change their gravity.

or yeah, you could just change the parent of the script to starter gui lol