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

Event Not Working, Touched is not A Valid Member of Model?

Asked by 6 years ago

So I made a health pack, and I used a simple function:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local hum = hit.Parent.Humanoid
        if hum.Health < hum.MaxHealth and hum.Health > 0 then
            hum.Health = hum.Health + 30
        end
    end
end)

But when I play the game it says, touched is not a valid of Model, and I mean obviously! Any idea what I did wrong, cause I'm obviously not trying to reference a part inside the pack.

Hope you can help, and thank you for your time.

0
Touched is nil in a model. This means that it doesn't even exist in models. Well, the event 'touched' or 'clicked' can only be used in parts. Try using the Base parts, so if you are using a model instead of a part, that won't work. Other than that, it might be a weird Studio glitch as it thinks that Touched is an object, not an event, and it sees that there are no objects called "Touched." mudathir2007 157 — 6y

4 answers

Log in to vote
1
Answered by 6 years ago

Your problem is that the touched event only works with parts. I have two suggestions to help you fix this problem. First: You might want to have the biggest part in the model have the touched event in it. Second(this is the one I recommend): Have a transparent part that is not CanCollidable cover the whole medpack and when it is touched fire the event. Hope this helps. Have a great day scripting!

0
To extend on this, make the brick the PrimaryPart of the model, then just change hit.Parent to hit.Parent.PrimaryPart WizyTheNinja 834 — 6y
0
Thanks you so much! FlippinAwesomeCrew 62 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

The .Touched event only works on parts, not models.

Log in to vote
0
Answered by
royee354 129
6 years ago
Edited 6 years ago

Hum = hit.Parent:FindFirstChild ("Humanoid") If Hum ~= nil then --script.Parent must be a part--

Log in to vote
0
Answered by 3 years ago

Hello Flippin, I know that you´ve solved this problem a while ago, but i want to put the solution i came up for my problem, with the help of: User#21908 WizyTheNinja Aaaand of course you.

in my case I want a platform to fade by the PrimaryPart when Touched.

  local part=script.Parent--the model
local fadingpart=part.Part--part i will have to fade
local active=false--debounce purposes
local function fading(OtherPart)
    local partparent=OtherPart.Parent--searching for a child in the part that touches the primary part
    local human=partparent:FindFirstChild("Humanoid")--this child have to be an Humanoid
    if not active and human then
        active=true--debounce purposes
        for n=1,10,1 do
            fadingpart.Transparency=n/10
            wait(0.2)
        end
        fadingpart.CanCollide=false
        wait(3)
        fadingpart.Transparency=0
        fadingpart.CanCollide=true
        active=false--debounce purposes
    end
end
part.PrimaryPart.Touched:Connect(fading)--triggered when the primary part is touched

If I´m misunderstanding something please tell me. Also, correct my writing if necessary. have a great night everyone.

Answer this question