How can I make my character be able to go on a block if I press a button?

1>What do I want to achieve in this?

Hi! I want my block to be collidable when I press a button. How can I do that?

2>What’s the issue?

First thing I did was search on Youtube and searched a bit on Google as well. But, couldn’t find anything which is the usual. So I tried making a script myself, and this is the closest I got:

workspace.AppearBlock.CanCollide = true --(Also, I figured out this script when I searched something related to this topic on Google, which said BasePart.CanCollide)

Any help please?

GOAL: Have a button that allows you to step onto the the “AppearBlock” when you click the button with your cursor. If you don’t press the button, you can’t step on the “AppearBlock”.

Is that all your code? We can’t really tell you how to fix it if you do not give us your whole script.

Also, when you paste the code into a message, please format it using CTRL+SHIFT+C after selecting the text.

I see you are new to scripting. While this can be achieved through many methods, imo ClickDetectors are the easiest way to start off. Check this article, I think it’ll be very useful!

Your script could look like this stub:

local clickable_part = -- reference to the part you want to click
local block = workspace.AppearBlock

clickable_part.ClickDetector.MouseClick:Connect(function()
	block.CanCollide = true
end)

And that’s it! When someone clicks (or taps) the “clickable_part” button, the block will be collidable.

If you don’t want to rely on ClickDetectors or wish to dig deeper on user inputs, take a look at this tutorial.

1 Like

Thanks a lot @mishajones! ____

1 Like

@mishajones
Oh wait! At, local Block = workspace.AppearBlock is showing an error.

It keeps underlining “local”, here’s what the error says in output:

18:14:00.487 - Workspace.clickable_part.ClickDetector.Script:2: Expected identifier when parsing expression, got 'local'

Did you define the variable ‘clickable_part’?

If not, then at line one, your code should look like this:
local clickable_part = script.Parent.Parent

1 Like

It’s supposed to be, if I press a button, a block should be able to be stepped on, which is the “AppearBlock”. The “clickable_part” is the button to make the part appear so I can step on it.

Look:
robloxapp-20200403-1632039.wmv (1.2 MB)

What does your code currently look like? I am confident I will be able to fix it up.

OH! You already did! Thank you! ^^

I wish I could make both of you solutions, but I can’t… :confused: Anyway, thanks a lot!

1 Like

Oh, alright. No problem. Don’t be hesitant to ever post anything else on the forum if you need any more help!

I know, but I’ll always put research into it before I ask. Thanks for the help! :smiley:

1 Like