Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make This type of touch trigger script?

I started scripting 1 day ago and I want To learn something simple. I want To make it so when you step on a block it makes another block Appear next to it.

2 answers

✓ Accepted answer

I'd suggest to watch youtube videos to learn basics of Lua, however I'll help you Make 2 Parts, Name First part: Part1 Name Second Part: Part2


local part1 = workspace.Part1
local part2 = workspace.Part2

part2.Transparency = 1

part1.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
       part2.Transparency = 0
end
end)

Here is how you could do it:

  1. Place the Part that is supposed to appear when a player touches another part.
  2. Change its transparency to 1 and its CanCollide property to false, so that players don't know there is a block and so that the players can walk right through it.
  3. Write the following code to make the other part appear:
local part = --Define where the part that is supposed to appear is
local touchedPart = --Define the part that is to be touched

local function onTouched() -- Define the function and what it should do
	part.Transparency = 0 -- Change the part's transparency back to 0 so its opaque
	part.CanCollide = true [[-- Change the part's CanCollide property to true so that players can
be able to stand on the part --]]
end

touchedPart.Touched:Connect(onTouched) -- Fires the function when the part is touched

Here is how it would look like if it were pure code:

local part = game.workspace.Part
local touchedPart = game.workspace.touchedPart [[-- Make sure to name both the parts differently so no errors occur--]]

local function onTouched()
	part.Transparency = 0
	part.CanCollide = true
end

touchedPart.Touched:Connect(onTouched) [[-- This fires the function above when the touchedPart is touched--]]

4 comments

0

What should it look like when I’m defining the part that is to be touched?

0

I’m having a little trouble on the define the function and what it should do. I dont Know how to type it out like in the correct way can you give me an example of what it should look like when I type Out what the function can do

0

I made some changes above. Maybe that will help?

0

Thanks man you really helped out

This discussion is preserved as it was. New answers, comments, and votes are closed.