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

How do I force players to sit and prohibits them to jump (onTouch)?

Hi!

I am the least experienced scripter in the history of scripters, and I am in need of help.

The thing I need is a brick which forces the player to sit, but prohibits them to jump.

This brick is to put at the start of a slide. I want the player to sit all the way through the slide down, so they can't simply jump and walk down.

A script I pulled out of the free models library (I'm sorry guys, if I could script myself, I would do it) already takes care of the sitting part:

enabled = true
function onTouched(hit)
	if not enabled then return end
	enabled = false 
	local h = hit.Parent:findFirstChild("Humanoid")
	if (h ~= nil) then
		h.Sit = true
	end
	enabled = true 
end 
script.Parent.Touched:connect(onTouched) 

It is possible that only a single line of code is enough to make this work, but unfortunately I have yet to be successful.

The player should be allowed to jump again when the bottom is reached (or if they die).

I hope someone can help me! Thanks in advance.

2 answers

Maybe try turning off the animation

--Turn off anim
enabled = true

function onTouched(hit)

	if not enabled then return end
	enabled = true
	local h = hit.Parent:findFirstChild("Humanoid")
	if (h ~= nil) then
		h.JumpPower = 0 -- DEFAULT IS 50
		h.Sit = true
		h.Animation.Disabled = true
		--[[ wait(5) TAKE OFF (--[[ and ]] if you want to return to normal after a certain amount of time.
		h.Animation.Disabled = false
		h.JumpPower = 50
		]]
	end
end

6 comments

0

Humanoid has tis property called 'jump power,' when set to 0, the player will be unable to jump. Revert it back to 50 for regular jump

0

Also findFirstChild is depricated use :FindFirstChild instead.

0

Thanks! It kind of works. When the brick is touched, I sit down, but I can get out of it anyways by jumping. I don't actually jump into the air, but it cancels out the sitting anyways. Any solution for that?

0

@Jesse, sorry I haven't been scripting for roughly 5 years now so I didn't know.

0

Turning down JumpPower will work, but using the Sitting property on the player is much more effective

0

Yes sir, but my script does exactly that

Maybe try this:

local shouldSit = true

function onTouch(obj)
	local human = obj.Parent:FindFirstChild("Humanoid") --Find humanoid

	if human then --If there is a player touching
		while shouldSit do --If they should sit
			human.Sit = true --Keep them sitting
			wait() --Make sure the program doesn't crash
		end
	end
end

script.Parent.Touched:Connect(onTouch)

If this didn't work, let me know and I'll debug it.

3 comments

0

Hi! Thanks for your response. It tells me that 'Sitting is not a valid member of Humanoid'. I tried changing 'Sitting' into 'Sit', but that crashed Studio.

0

Here, I edited the code. I know why it crashed, and you are right. It is Sit, not sitting.

0

It works better now, but still not quite. Holding space lets me jump and move where I want to, although my character desperately tries to sit down again. I even combined your script with a JumpPower of 0, but that also takes the character out of 'sit-mode'.

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