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

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

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.

4 comments

0

Did you parent this script into a seat, If so why not try script.Parent.Touch function?

0

maybe you're right i will try that

0

It did not work, here is the code i tried:

0

local seat = script.Parent seat.Touched:Connect(function(hit) local char = hit.Parent local hum = char.Humanoid hum.JumpPower = 0 end)

2 answers

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!

1 comment

0

Yeah, it worked

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)

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