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

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

Asked by
FBS_8 25
4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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)
Ad
Log in to vote
0
Answered by 4 years ago
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.

0
it seems to sometimes work and sometime not work? FBS_8 25 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

Answer this question