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

FireClient: player argument must be a Player object, sometimes it works sometimes it doesnt?

script:

wait(1)
local event1 = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
local db = false

script.Parent.Touched:Connect(function(hit)
    if db == false then
    local character = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        db = true
        event1:FireClient(player)
        print("event fired")
        wait(3)
        db = false
    end
end)

3 answers

local eventA = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
local db = false

script.Parent.Touched:Connect(function(hit)
    if db == false then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        db = true
        eventA:FireClient(player)
        print("event fired")
        wait(3)
        db = false
    end
    end
end)
local event1 = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
local db = false

script.Parent.Touched:Connect(function(hit)
    if db == false then
	local character = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        db = true
        event1:FireClient(player)
        print("event fired")
        wait(3)
        db = false
    end
end)

If this doesn't work then check if touched part has humanoid.

1 comment

0

it seems to sometimes work and sometime not work?

What I'm assuming here is that if the part is touching something other then a player then it's trying to get the player from that, and because it's not a player, it's giving you this error.

If you want this to only work if a player touches the part you can do this:

wait(1)
local event1 = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
local db = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if db == false then
			local character = hit.Parent
			local player = game.Players:GetPlayerFromCharacter(character)
			db = true
			event1:FireClient(player)
			print("event fired")
			wait(3)
			db = false
		end
	end
end)

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