I have a platform in my game that, when touched, shakes, then falls down, only to reset right after. However, if the player steps off the platform before it falls, the platform just stays in midair, and it’ll fall down after a couple seconds, or the player steps on it again.
This is the script. If it helps, it's a LocalScript inside StarterPlayerScripts.
local parent = game.Workspace.FlimsyPlatform1
local pos = Vector3.new(-163.5, 8.5, -253.5)
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local rumble = game.Workspace.ShortRumble
local crash = game.Workspace.Crash
local debounce = false
parent.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if (player and player == localPlayer) and not debounce then
debounce = true
parent.Position = parent.Position + Vector3.new(1, 0, 0)
rumble:Play()
wait(.25)
parent.Position = parent.Position + Vector3.new(-2, 0, 0)
rumble:Play()
wait(.25)
parent.Position = parent.Position + Vector3.new(2, 0, 0)
rumble:Play()
wait(.25)
parent.Anchored = false --This is where the platform is supposed to fall.
crash:Play()
wait(5)
parent.Anchored = true
parent.Orientation = Vector3.new(0, 0, 0)
parent.Position = pos
debounce = false
end
end)
The rusty platform at the top right corner is supposed to fall down.
What do you want to achieve? I want to have the platform fall down.
What is the issue? The platform doesn’t fall down, and I don’t know why.
What solutions have you tried so far? I tries looking for similar topics, but could not find anything.
The script works perfectly fine, the only thing wrong being the platform not falling when it’s supposed to. Any help is appreciated
I mean, when a player interferes - if I step on it while it is falling, will it stop, keep falling, or reset position? I already know the behaviour when a player doesn’t interact, and when the player interacts right before it falls, as you described it above. I want to know some other cases and what happens.
Alright, I would recommend printing the value of debounce.
local parent = game.Workspace.FlimsyPlatform1
local pos = Vector3.new(-163.5, 8.5, -253.5)
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local rumble = game.Workspace.ShortRumble
local crash = game.Workspace.Crash
local debounce = false
parent.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if (player and player == localPlayer) and not debounce then
debounce = true
print(debounce) -- right here!
parent.Position = parent.Position + Vector3.new(1, 0, 0)
rumble:Play()
wait(.25)
print(debounce) -- right here!
parent.Position = parent.Position + Vector3.new(-2, 0, 0)
rumble:Play()
wait(.25)
print(debounce) -- right here!
parent.Position = parent.Position + Vector3.new(2, 0, 0)
rumble:Play()
wait(.25)
print(debounce) -- right here!
parent.Anchored = false --This is where the platform is supposed to fall.
crash:Play()
wait(5)
parent.Anchored = true
parent.Orientation = Vector3.new(0, 0, 0)
parent.Position = pos
debounce = false
end
end)
I’m curious to see if the debounce is resetting itself for some reason. Looking at your code it should be fine, but doesn’t hurt to check.
Yes but the whole point of this is to check two things - the value, and if it prints again when you step on it. If it isn’t printing 8 times when you step on it a second time, and it doesn’t fall, then perhaps you have a duplicate script or another listener? Because otherwise, the event function doesn’t go through.
Well then, either your debounce variable is behaving weird (and so I’m not sure what’s going on), or you have the same script somewhere else that keeps replicating? I’m sorry to say, I don’t really know why your debounce isn’t behaving the way it should. Perhaps someone could shed some light that we are missing.
When a part is touched, the platform shakes, then becomes unanchored, and is supposed to fall. If the player steps off the part while it is shaking, but not falling, the part just stays in mid air, yet still unanchored. It either falls after a couple of seconds, or falls when the player touches it again before it resets. I want the part to fall immediately when it’s unanchored, not a bit after.
GalaxyGourmet has a platform that wobbles for a second, then falls (unanchored). The falling portion has a 5 second cooldown and he has as debounce in place that resets once the platform has been anchored (after it falls). The platform then resets position.
This issue is that if a player steps on the platform while it is wobbling, it bypasses the falling portion and keeps the platform up.
The debounce is not the problem. It behaves exactly fine, and prints what it’s supposed to print.
If it does help, however, there are 3 other platforms near the one showed in the picture in my post. I made three other scripts for those ones too, but I am almost certain that this isn’t the problem, as the scripts are for their own separate platforms.
Edit: I also can confirm that the extra scripts are not the problem because I unanchored a ball with a MouseClick event, and it did the same thing.
Have you tried messing around with the positions of some of the code? Like changing the position of crash:Play() so that it’s fired before the part gets Unanchored? This might not be it, but It’s worth a try.