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

I made a LocalScript that if the player sits, his jumppower will be set to 0. What did i do wrong?

Asked by 5 years ago
local player = game.Players.LocalPlayer


if not player.Character then
    print("waiting for character")
    player.CharacterAdded:wait();
    char = player.Character
else
    char = player.Character
end
local hum = char.Humanoid
if hum.Sit == true then
    print("Player is sitting")
    hum.JumpPower = 0
end

This script is in a LocalScript, in StarterPlayerScripts.

The goal of my script is that if a player sits, that his jumppower will be set to 0.

0
Did you parent this script into a seat, If so why not try script.Parent.Touch function? rochel89 42 — 5y
0
maybe you're right i will try that BaconX112X 75 — 5y
0
It did not work, here is the code i tried: BaconX112X 75 — 5y
0
local seat = script.Parent seat.Touched:Connect(function(hit) local char = hit.Parent local hum = char.Humanoid hum.JumpPower = 0 end) BaconX112X 75 — 5y

2 answers

Log in to vote
1
Answered by
starmaq 1290 Moderation Voter
5 years ago

Here is another simpler way, the seat has an awesome property called occupant, which is whoever sat on the seat, if no one is currently sitting, it will be nil. So if we use this with a .Changed event which checks if a property has changed. We can check if the occupant property has changed, and if it has changed and the occupant is a player, we set his jumppower to 0! And btw, your script is actually right, but the if statments are only checking once if the humanoid sitting, because if statments always check a condition once, so you have to put them inside of a loop or something so they contanly check. But this way is more efficient I think. The paramater for the changed event is whatever property was changed. And the occupant is actually the humanoid that is sitting.

local seat = script.parent

seat.Changed:Connect(function(prop)
    if prop == "Occupant" then
        if seat.Cccupant:IsA("Humanoid") then
            local humanoid = seat.Occupant 
            humanoid.JumpPower = 0
        end
    end
end)

And that should work!

0
Yeah, it worked BaconX112X 75 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Pretty simple line of code put a script inside a seat and then put this in.


script.Parent.Touched:Connect(function() wait(0.5) script.Parent.SeatWeld.Part1.Parent.Humanoid.JumpPower = 0 end)

Answer this question