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

OnTouched with Filtering Enabled problem?

Asked by
NotSoNorm 777 Moderation Voter
9 years ago

It's a remoteEvent (Because I have to change a gui)

What's wrong? I keep getting the error 'Unable to cast value to Object' Line 8

local deb = false

function onTouch(part) 
    if deb == false then
        deb = true
        local human = part.Parent:findFirstChild("Humanoid") 
        if (human == nil) then return end 
            script.Parent.RemoteEvent:FireClient(human.Parent.Name)
            wait(1)
            deb = false
    end 
end
script.Parent.Touched:connect(onTouch) 

1 answer

Log in to vote
2
Answered by
Lacryma 548 Moderation Voter
9 years ago

You're using the RemoteEvent wrong. You cannot pass in a name in the FireClient method. Instead a player must be passed into the method. In this instance I'll use the GetPlayerFromCharacter method of game.Players to fulfill this.

local deb = false

function onTouch(part) 
    if deb == false then
        deb = true
        local human = part.Parent:findFirstChild("Humanoid") 
    if human then
            local player = game.Players:GetPlayerFromCharacter(human.Parent)
        if player then
                 script.Parent.RemoteEvent:FireClient(player)
                 wait(1)
                deb = false
        else
            wait(1)
            deb = false
        end
    else
        deb = false
    end
    end
end
script.Parent.Touched:connect(onTouch) 
0
thx NotSoNorm 777 — 9y
Ad

Answer this question