Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make something appear when a player walks over it?

Asked by 7 years ago

Okay so, (first post yay

3 answers

Log in to vote
0
Answered by
arolh3 5
7 years ago
Edited 7 years ago

Aaalrighty, so I'm guessing you know very little/nothing about lua, so i'll try to explain in a way that will make sense

Put a script in the block you want to make appear,

Make it transparent,

The code:

``iTouched = false -- a Variable so it doesnt fire the function multiple times when you touch it

function onTouch(hit) if not iTouched then -- if I was touched then run the code iTouched = true

script.Parent.Transparency = 0 -- The parent's transparency = 0

wait(2) -- this time is adjustable
iTouched = false

end

end

script.Parent.Touched:connect(onTouch) -- Runs the function

Hope this helps

~~~~~~~~~~~~~~~~~

0
I really have no idea why my answer has only part of the code registered, just made my account today rip arolh3 5 — 7y
Ad
Log in to vote
0
Answered by
deris88 146
7 years ago

That's a very easy script:

--deris88

--Create a Part and insert this script  into it:

local Part = script.Parent

Part.Transparency = 1
Part.Touched:connect(function()
    Part.Transparency = 0
end)


Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Hello, and welcome to the site.

Lua is a very easy language compared to others. Roblox uses a modified version of this referred to as RBX.Lua. Roblox has added their own functions and tons of events.

We'll be using the Touched Event. I'm going to assume you have a brick in workspace. This will be the part we're going to be scripting.

To begin scripting, first insert a script into the part. Make sure it's a regular script, not a Local Script or Module Script. I'm assuming you already know how to do this, it's just best to make sure.


Now for the scripting!

We'll use a variable even through you really don't need to. A variable can be named anything, and stores information. That's all you really need to know about variables right now.

-- Assuming the script is inside the part
local part = script.Parent

Script is a pre-definedvariable made by the script that refers to itself. Using Parent, or .Parent, gets whatever a object is inside. So for example, if we were to use .Parent on the part variable we just made, we would get workspace because the part is inside workspace.


So now that we have the part, let's use the Touched event to activate more code in the future.

-- Assuming the script is inside the part
local part = script.Parent

part.Touched:connect(function()
    --Code later
end)

What I used above is an anonymous function. The other way of writing the same thing would be like this,

-- Assuming the script is inside the part
local part = script.Parent

function Touched()-- Touched can be named anything
    --Code later
end

part.Touched:connect(Touched)--Call whatever you named your function

But I'll be using the first method because it's shorter.


Now we can do whatever we want inside the script when the part is touched. Let's make it visible for 5 seconds, and then disappear again.

-- Assuming the script is inside the part
local part = script.Parent

part.Touched:connect(function()
    part.Transparency = 0-- Visible
    wait(5)
    part.Transparency = 1-- Not Visible
end)

Cool!

It's important to understand that anything can touch this part to make this event fire. If you need this to only fire when a player or character touches the part, I would suggest asking another question.


Reminder,

This is not a request site, and you should provide your attempts on the problem and provide evidence that you have attempted this problem before submitting the question.

Good Luck!

Whoever helped you the most, don't forget to accept their answers. I'm sure they would greatly appreciate it.

Answer this question