I am trying to replicate this thing I saw in an obby from a little while ago, and it was this part where if you inside/touching the part it would cause you to jump, and I made it work using Humanoid:ChangeState(Enum.HumanoidStateType.Jumping). However, the script I made is only firing via command bar, even when putting :WaitForChild() in there, it still does not work. The thing I find very weird is that it still prints the print statement, it just does not force the player to continually jump. If you can help me that would be awesome. But one more thing, sometimes the player falls when they are just walking on it, and I am unsure how to fix that, so if you have any ideas let me know!
Script (Inside of ServerScriptService [Works when pasted into the command bar]):
local Zone = require(game:GetService("ReplicatedStorage").Zone)
local container = workspace:WaitForChild("RandomModel")
local zone = Zone.new(container)
local run = game:GetService("RunService")
local activeConnections = {}
zone.playerEntered:Connect(function(player: Player)
print(("%s entered the zone!"):format(player.Name))
local connection = run.Heartbeat:Connect(function()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char and char:FindFirstChildOfClass("Humanoid")
if hum and hum:GetState() ~= Enum.HumanoidStateType.Jumping then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end)
activeConnections[player] = connection
end)
zone.playerExited:Connect(function(player: Player)
print(("%s exited the zone!"):format(player.Name))
if activeConnections[player] then
activeConnections[player]:Disconnect()
activeConnections[player] = nil
end
end)