Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
Infocus 144
4 years ago
Edited 4 years ago

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
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 Infocus 144 — 4y
0
Also findFirstChild is depricated use :FindFirstChild instead. JesseSong 3916 — 4y
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? Allineate 22 — 4y
0
@Jesse, sorry I haven't been scripting for roughly 5 years now so I didn't know. Infocus 144 — 4y
View all comments (2 more)
0
Turning down JumpPower will work, but using the Sitting property on the player is much more effective Nckripted 580 — 4y
0
Yes sir, but my script does exactly that Infocus 144 — 4y
Ad
Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
4 years ago
Edited 4 years ago

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.

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. Allineate 22 — 4y
0
Here, I edited the code. I know why it crashed, and you are right. It is Sit, not sitting. Nckripted 580 — 4y
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'. Allineate 22 — 4y

Answer this question