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

OnTouched with Filtering Enabled problem?

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

✓ Accepted answer

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) 

1 comment

0

thx

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