Hello! I currently am working on a trampoline script, where the player enters a hitbox, he gets Jump Points and his humanoid jumps till a variable is false. The jumping and points giving is controlled in a while loop, and the issue im having is if I set the variable “isOnTramp1” to false, the humanoid keeps on jumping. How would I fix that? Upon entering the HitBox, you also get a “Leave” Button, that should handle the teleporting outside of the trampoline and stopping the character from jumping.
local rs = game:GetService("ReplicatedStorage")
local events = rs:WaitForChild("Events")
local tramp1 = game.Workspace:WaitForChild("Trampoline1")
local debounce = false
local player = game.Players.LocalPlayer
local plrGui = player:WaitForChild("PlayerGui")
local isOnTramp1 = false
local tramp1Leave = plrGui:WaitForChild("TrampsLeave"):WaitForChild("Tramp1Leave")
tramp1:WaitForChild("Hitbox").Touched:Connect(function(hit)
local hum = hit.Parent:WaitForChild("Humanoid")
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if debounce == false then
if hum then
debounce = true
tramp1:WaitForChild("Hitbox").CanTouch = false
tramp1.Bill.BillboardGui.Enabled = false
tramp1.Required.BillboardGui.Enabled = false
char:WaitForChild("HumanoidRootPart").CFrame = tramp1:WaitForChild("Mat").CFrame + Vector3.new(0, 3, 0)
for _, part in pairs(tramp1:WaitForChild("Walls"):GetChildren()) do
if part.Name == "InvisWall" then
part.CanCollide = true
end
end
wait(0.3)
events.PlayerJump:FireServer()
isOnTramp1 = true
tramp1Leave.Visible = true
while isOnTramp1 do
events.TrampJump:FireServer(tramp1:WaitForChild("PerJump").Value)
hum.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Landed or oldState == Enum.HumanoidStateType.Landed then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end)
wait(1)
end
print(isOnTramp1)
wait(1)
debounce = false
end
end
end)
tramp1Leave.MouseButton1Up:Connect(function()
tramp1Leave.Visible = false
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
isOnTramp1 = false
hum:ChangeState(Enum.HumanoidStateType.Landed)
hrp.CFrame = tramp1:WaitForChild("OutsideTP").CFrame + Vector3.new(0, 3, 0)
print(isOnTramp1)
end)
This is the script. If you need more information, feel free to ask. I am a beginner, don’t expect the best code. Have a good one!