I have decided I will learn Lua, and today is my first day. This is also my first post.
I am going through script tutorials at the moment, I figured it would be good to go through some of these before really getting into it.
I tried to change my head's transparency in Studio Mode "Play" Mode, but whenever I try to put it in the Command Bar it tells me that "fretfatberger2" is not a part of Workspace.
EDIT: Every time I try to put in a script in Studio mode and play it or go in solo it isnt working. I tried to make a brick remove itself when it is touched, it isnt working and I cant figure it out. Here is the script I used.
function touch() script.Parent:remove() end script.Parent.Touched
script.Parent.Touched:connect(touch)
every event i think has a line called the connection line which connects it to the function
to make your head transparent you can do the following this is inside the touch function and give the touch function a parameter of hit . Hit is the part that touched script.Parent
function touch(hit) local humanoid=hit.Parent:findFirstChild("Humanoid") if humanoid ~= nil then hit.Parent.Head.Transparency=1 end end script.Parent.Touched:connect(touch)
hit.Parent.Head.Transparency=1
the Character model is the parent of the part that hit it which most likely the right or left leg Head is a child of the character and transparency is a property of head.
local humanoid=hit.Parent:findFirstChild("Humanoid")
we want to make sure the object hitting script.Parent
has a humanoid inside them.
What you're missing here is something called the connection statement.
A connection statement
ties a function to an event, making it so that something actually happens when the event activates - so it's essential in making something happen like when you touch a brick.
Also, the remove()
method is deprecated, use the Destroy()
method instead!
function touch() script.Parent:Destroy() end script.Parent.Touched:connect(touch) --connect the function 'touch'
Most if not all objects in Roblox have events, just like they have properties. script.Parent.Transparency is a property. script.Parent.Touched is an event. As there are different properties for different objects, there are also different events for different objects. Touched is an event specifically for parts. Upon events being triggered, you may call upon a previously declared function, in this case "touch". script.Parent.Touched:connect(touch) states that if the part is touched, call the "touch" function to destroy script.Parent.
Basically, "script.Parent.Touched" should be "script.Parent.Touched:connect(touch)".