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

How do i fire a remote event in a OnTouched function?

Asked by 4 years ago
Edited 4 years ago

I want a script where a player touches a brick, and then a gui pops up

Here's a script

-- script
script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    game.ReplicatedStorage.MMEvent:FireClient(player)
end)
-- local script
game.ReplicatedStorage.MMEvent.OnClientEvent:Connect(function(player)
local frame = script.Parent.Parent
        Frame.Visible = true
end)

for some reason the output says "player argument must be a Player object"

0
Explain what is wrong with it. AlertShamrock 37 — 4y
0
After line 3, put "if not player then return end" Shawnyg 4330 — 4y

1 answer

Log in to vote
0
Answered by
174gb 290 Moderation Voter
4 years ago
Edited 4 years ago

You need check if who touched is a player

(in my opinion, the best way would be:)

-- script
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then  -- check if who touched "have" humanoid
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        game.ReplicatedStorage.MMEvent:FireClient(player)
    end
end)

Ad

Answer this question