Hello! It’s me, @commandshift71, back to scripting support yet again with another question that probably has a stupidly obvious answer!
I’m currently making my first game-yay!-and i’m trying to have events occur only after the player has passed through this doorway. I’ve done so using an invisible barrier between the two sides of the doorway, that becomes solid once the player passes through it.
Thing is there is one issue. I would have to script everything else in the game within this code snippet.
[ this is a localscript in starterplayerscripts, fyi ]
game.Workspace.TouchPart.Touched:Connect(function()
task.wait(1.4)
game.Workspace.AntiPart.Transparency = 0
game.Workspace.AntiPart.CanCollide = true
game.Workspace.AntiPart.Material = Enum.Material.Brick
textToChange.Text = "Hope you went all the way through, because if you didn't, you'd have to leave and rejoin the game! ;)"
task.wait(8)
textToChange.Text = "Now, you'll have to go through each level and press a glowing white button to progress."
task.wait(8)
textToChange.Text = "In this room, it's just an example button. You're welcome."
task.wait(4)
textToChange.Text = " "
end)
I’ve tried to use task.wait and just hoping the player goes through the doorway, but i don’t want to rely on that.
local part = script.Parent
local clickDetector = part:FindFirstChildOfClass("ClickDetector")
local function onClick()
part.BrickColor = BrickColor.Random()
end
if clickDetector then
clickDetector.MouseClick:Connect(onClick)
end
well, add a debounce that is true after touch so it never fires again, altoguh inside one function then I mean it would work. OR
you can make a value in workspace called “started” and set it true when the player touches.
in other scripts you can detect when it’s true and then proceed with the events.
It works! I wasn’t sure what a debounce was, so i checked documentation and figured it out from there!
I simply added a value that is false, and then upon touch, an if statement checks to see whether the value is false. If it is, it proceeds, and changes the value to true. If it’s already true then nothing happens. Still not sure if that’s debouncing, but it works!