Is there a better way to execute this?

Hello! It’s me, @commandshift71, back to scripting support yet again with another question that probably has a stupidly obvious answer! :wink:

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.

2 Likes

its only make the smarter… that not harder and

2 Likes

ᘏᐅ cᐊᐣ ᑓᗟcᐪ ᗙᐣ pᘧᘑr ᗰᐈᔆ ᐪᑋrᐃᐅᐦ ᑌr ᐊᐣd ᑎ ᐪᐶ ᐈvᐈᐣᐪᔆ ᐉᐣᙒᑓ ᐪᐶ ᑓᗟcᗠᐃᐣ.

2 Likes

what???

2 Likes

You can detect when the player passes through the door, and then put your events inside the detection function.

3 Likes

local part = script.Parent

local function onClick()
    part.BrickColor = BrickColor.Random()
end

part.Touched:Connect(onClick)

2 Likes

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

2 Likes

Go try it, maybe would work the script

1 Like

Not to be rude, but i don’t think either of those are relevant?

1 Like

I promise you got to write it Try it

2 Likes

So what i’m doing is fine? I just feel like it’d be strange to put all the scripts for the game inside one :touched function…

1 Like

It’s meaning like a script when you’re adding in the game and then most click

1 Like

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.

2 Likes

That is the right answer of the question will work try it adding a script and well done we’re just we will try it

2 Likes

Thanks, i’ll try that.

3 Likes

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!

2 Likes

yea it’s the exactuis of debounceir.

1 Like

Instead of complicating, use Touched:Once

2 Likes

What’s Touched:Once? Does it literally just fire once, without debouncing?

1 Like

Yes. I suggest giving it a try.

2 Likes