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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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.

Ad
Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

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)

0
workspace? yogamer13294456 13 — 5y
0
what do you mean royaltoe 5144 — 5y
0
like where to put it yogamer13294456 13 — 5y
0
yeah go for it just make sure its a normal script not a local script royaltoe 5144 — 5y
View all comments (5 more)
0
kk yogamer13294456 13 — 5y
0
how'd it go? royaltoe 5144 — 5y
0
did it work? if so, please accept. otherwise, tell me and we can get it working. royaltoe 5144 — 5y
0
did not work sory for late yogamer13294456 13 — 5y
0
no worries. what happens instead of it working? royaltoe 5144 — 5y

Answer this question