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

How do I fix FireClient: player argument must be a Player object?

I really don't know what to do. I've tried doing local Player = game.Players.LocalPlayer instead of this code, but it said it must be a Player object.

local debounce = false
function onTouched(part,Player)
	if debounce == false then
	if part.Name == "Handle" then
	    debounce = true
	    script.Parent.GlassBreak:Play()
		script.Parent.Transparency = 1
	    script.Parent.CanCollide = false
	    game.ReplicatedStorage.PharmacyVandalism:FireClient(Player)
	    wait(.1)
	    debounce = false		
	   end
	end
end
script.Parent.Touched:Connect(onTouched)

1 answer

The BasePart.Touched event doesn’t give you the player who touched the BasePart just another part. Since all parts in a player’s character are direct children of it, you use the Players:GetPlayerFromCharacter() function get the player from the character, the character is retrieved directly from the part:


local isTouching = false

function onTouched(part)
    local player = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
    if not player then return end

    -- Now we know the part is from a character
    if not isTouching then
		if part.Name == "Handle" then
			isTouching = true
			script.Parent.GlassBreak:Play()
			script.Parent.Transparency = 1
			script.Parent.CanCollide = false
			game.ReplicatedStorage.PharmacyVandalism:FireClient(player)
			wait(.5)
			isTouching = false 
		end       
	end
end

script.Parent.Touched:Connect(onTouched)

6 comments

0

00:58:48.588 - players is not a valid member of DataModel

0

try game:GetService("Players"):FindFirstChild(part.Parent.Name)

0

i edited the script to show the changes

0

It doesn't work. The code isn't even executed.

0

Any output? @royaltoe why are you editing my answers without my permission? Your edit is also completely redundant since the method GetPlayerFromCharacter has perfect usage here. Your own implementation doesn’t differ the result.

0

There is no output

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