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
5 years ago
Edited 5 years ago

script:

01wait(1)
02local event1 = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
03local db = false
04 
05script.Parent.Touched:Connect(function(hit)
06    if db == false then
07    local character = hit.Parent
08        local player = game.Players:GetPlayerFromCharacter(character)
09        db = true
10        event1:FireClient(player)
11        print("event fired")
12        wait(3)
13        db = false
14    end
15end)

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01local eventA = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
02local db = false
03 
04script.Parent.Touched:Connect(function(hit)
05    if db == false then
06if game.Players:GetPlayerFromCharacter(hit.Parent) then
07        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
08        db = true
09        eventA:FireClient(player)
10        print("event fired")
11        wait(3)
12        db = false
13    end
14    end
15end)
Ad
Log in to vote
0
Answered by 5 years ago
01local event1 = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
02local db = false
03 
04script.Parent.Touched:Connect(function(hit)
05    if db == false then
06    local character = hit.Parent
07        local player = game.Players:GetPlayerFromCharacter(character)
08        db = true
09        event1:FireClient(player)
10        print("event fired")
11        wait(3)
12        db = false
13    end
14end)

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 — 5y
Log in to vote
0
Answered by 5 years ago
Edited 5 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:

01wait(1)
02local event1 = game.ReplicatedStorage.Events:FindFirstChild("GuiEvent")
03local db = false
04 
05script.Parent.Touched:Connect(function(hit)
06    if hit.Parent:FindFirstChild("Humanoid") then
07        if db == false then
08            local character = hit.Parent
09            local player = game.Players:GetPlayerFromCharacter(character)
10            db = true
11            event1:FireClient(player)
12            print("event fired")
13            wait(3)
14            db = false
15        end
16    end
17end)

Answer this question