Touched Event - not working properly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve it so when you touch this green part, the top image label turns grey, and the bottom turns red, with a smooth effect which is where I’ve got, but it doesn’t turn to red.

  2. What is the issue? Include screenshots / videos if possible!
    It is failing to work at the moment, causing issues.
    Development Bug - YouTube

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I asked a friend, provided some code and he couldn’t figure it out.


1 Like

could you please copy the script lines and paste it here? so that it could be easier to modify it?

local part = script.Parent
local humanoid
local Sensor1 = script.Parent
local Signal = script.Parent.Parent

part.Touched:Connect(function(other)
if other.Parent ~= nil then
humanoid = other.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
script.Parent.Touched:Connect(function()
script.Parent.Parent.Part.SurfaceGui.TopLabel.ImageColor = (15, 15, 15)
script.Parent.Parent.Part.SurfaceGui.BottomLabel.ImageColor = (255, 0, 0)
end)

if humanoid then
humanoid.Died:Connect(function()
part.Touched:Disconnect
end)
end
  1. You don’t need to disconnect it, you could have a debounce instead.
  2. try this
local part = script.Parent
local Sensor1 = script.Parent
local Signal = script.Parent.Parent

part.Touched:Connect(function(other)
if other.Parent ~= nil then
local humanoid = other.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
      script.Parent.Parent.Part.SurfaceGui.TopLabel.ImageColor = (15, 15, 15)
      script.Parent.Parent.Part.SurfaceGui.BottomLabel.ImageColor = (255, 0, 0)
   end
end


Got an error still.

you should probably end the scripts

theres two ends there,
image

part.Touched:Connect(function(other)
	if other.Parent ~= nil then
		local humanoid = other.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid then
			script.Parent.Parent.Part.SurfaceGui.TopLabel.ImageColor = (15, 15, 15)
			script.Parent.Parent.Part.SurfaceGui.BottomLabel.ImageColor = (255, 0, 0)
		end
	end
end)


I believe I got an error, but I don’t get why

It says
“Expected ‘end’ (to close ‘then’ at line 9), got < eof >; did you forget to close ‘fundction’ at line 16?”
You’re missing some parameters and some end parts of the script

How many would be needed? I added one you said.

Not sure, mind pasting the script so I can see where the errors are?

local part = script.Parent
local Sensor1 = script.Parent
local Signal = script.Parent.Parent

part.Touched:Connect(function(other)
if other.Parent ~= nil then
local humanoid = other.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
      script.Parent.Parent.Part.SurfaceGui.TopLabel.ImageColor = (15, 15, 15)
      script.Parent.Parent.Part.SurfaceGui.BottomLabel.ImageColor = (255, 0, 0)
   end
end
end)

You sure that’s all of it? I’ve counted 13 lines while the error appears to be on line 16

This was the original code that I had before changing to the one above.

Okay, what is the script trying to do? The script is a bit of a mess and would probably be easier for me to make a new one

Basically, when you touch the green part, the signal turns from green to red in a smooth transition. This was a temporary thing until I figured out how to make a signalling system like the UK, look it up but I don’t have the skill for that.

local part = script.Parent
local colorChanger =  workspace.Part --("The thing changing colors I guess")

---Tween Service is pretty complicated so if you want to use it in an different script I'd advise you to watch a tutorial---
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)

local changeTheColorSmoothly = TweenService:Create(colorChanger, info, {Color = Color3.fromRGB(255, 0, 0)})
----------------------------------------------------------------------------------------------------------------------------

part.Touched:Connect(function(hit)
	if hit.Parent then
		if hit.Parent:FindFirstChild("Humanoid") then
			changeTheColorSmoothly:Play()
		end
	end
end)

Just telling you I haven’t seen anything about the UK signaling system

1 Like

the codes are kinda messy, try and clean it up / beautify it, then resend the code
also remember to end and use parentheses

Aside from some logical problems your code also has some syntactical problems.

ImageColor does not exist only ImageColor3 and if its a TextLabel ImageColor3 isn’t even an option maybe TextColor3 or BackgroundColor3?
Also using strings or tupples aren’tt the correct type of data, you would need to make from the Color3 type so Color3.fromRGB(15, 15, 15)