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 fire a remote event in a OnTouched function?

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"

2 comments

0

Explain what is wrong with it.

0

After line 3, put "if not player then return end"

1 answer

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)

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