Hi
I have a text label which is on a part. I would like the text label to change when a player runs into the part. I am trying to do this through a script which is a child to the part and which uses the ontouched function. However I can't find the right way to refer to the label. When I run the below code I get a message saying "SurfaceGui is not a valid part of MeshPart".
I've tried to paste a screenshot of the game layout but no luck. So I've described it using text
1) Workspace is parent to Part 2) Part is parent to a script (which is below) 3) Part is also parent to SurfaceGui 4) SurfaceGui is parent to Textlabel.
Thank you
Chris
************* Code starts *****************************
function onTouched(part)
local var = part.SurfaceGui.Frame.TextLabel -- code to change the label will come here
end
script.Parent.Touched:connect(onTouched)
************* Code Ends *****************************
Thanks in advance for your help
Chris
script.Parent.Touched:Connect(function(part)..whejn its touched if part.Parent:FindFirstChild("HumanoidRootPart") then--if its a player that touches it script.Parent.SurfaceGui.TextLabel.Text = "Text here"--then it changes this end end)
So, I'm not very good at explaining stuff so...
script.Parent.Touched:Connect(function(p) --This is an event. Like a click detector, touched, etc. It would trigger if it got touched. local humanoid = p.Parent:FindFirstChild("Humanoid") --this would check if the object who touched it, has a Humanoid in it. Meaning a player. if humanoid then -- this is an if statement, the code would only pass if it's true... local var = game.Workspace.Part.SurfaceGui.Frame.TextLabel --You need to tell the script where the part exactly where it is, you need to start with "game" Also. You can't have 2 parts having the same name in a script.. that would confuse the script, I recommend you change parts names... var.Text = "Add here" end -- the end for the "if statement". end) -- this is an end for the event. it ends with a ")" (forgot the name of it... lol)
Have a good day!
P.S remove the comments (the ones that start with 2 divides (--) or don't.. it doesn't really matter..