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

'Touched is not a valid member of Model'?

Trying to fix an error I've been getting with onTouched and I get a new error.

Suggestions?

local Player = game.Players.LocalPlayer
local mouse = script.Parent.Parent:GetMouse()
local char = Player.Character or Player.CharacterAdded:Wait()

function onKeyPress(key)
	key = key:lower()
	if key == "r" then


local RSW = game.Lighting.RMOVE.RSW:Clone()
RSW.Parent = game.Workspace
RSW.Transparency = 1
wait(0.6)
RSW.Anchored = true
RSW.Transparency = 0
function onTouch(hit) -- <<------
		RSW.Color = hit.Parent.Color
	end

mouse.KeyPress:connect(onKeyPress)
char.Touched:connect(onTouch)

What I'm trying to do is change the color of RSW to whatever color your character is standing on. E.g. You stand on a grey floor so RSW will be grey, then you walk over to a green floor so RSW will be green, hope you're following.

Any advice is advice so I appreciate it nonetheless.

1 answer

✓ Accepted answer

.Touched is an event that only applies to parts. Meaning you cannot call .Touched on a model. Solutions include making it a .Touched on one of the legs or running a function like:

for i, v in pairs (char:GetChildren()) do
	if v:IsA('BasePart') then
		v.Touched:connect(onTouch)
	end
end

Read more about it here: http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched

1 comment

0

This was a really helpful answer! Thanks!

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