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

turn off a script while sitting and turn it back on while standing?

when i test it, it wont work

--when you sit you disable a script
game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Sit:Connect(function()
	    script.CameraScript.Disabled = true
end)
end)
end)

--when you stand you enable a script
game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").stand:Connect(function()
	    script.CameraScript.Disabled = false
end)
end)
end)

2 answers

Try this:

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Sit"):Connect(function()
			if character.Humanoid.Sit then
				script.CameraScript.Disabled = true
			else
				script.CameraScript.Disabled = false
			end
		end)
	end)
end)

This code works for me when I test it.

You only need one PlayerAdded function. You can put all your logic in there. Also, the event to see if a player is seated is 'Seated' , not 'Sit' Seated has a parameter that is true/false depending on if the player is seated or not.

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Seated:Connect(function(isSeated)
			if(isSeated)then
				print("Player is seated")
				script.CameraScript.Disabled = true
			else
				print("Player is NOT seated")
				script.CameraScript.Disabled = false
			end
		end)
	end)
end)

9 comments

0

workspace?

0

what do you mean

0

like where to put it

0

yeah go for it just make sure its a normal script not a local script

0

kk

0

how'd it go?

0

did it work? if so, please accept. otherwise, tell me and we can get it working.

0

did not work sory for late

0

no worries. what happens instead of it working?

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