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

'Touched is not a valid member of Model'?

Asked by
kfish98 16
7 years ago

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

Log in to vote
1
Answered by 7 years ago

.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

0
This was a really helpful answer! Thanks! kfish98 16 — 7y
Ad

Answer this question