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

I'm trying to make a GUI appear when you touch a brick, the output says this is the issue. Help?

local p = script.Parent

p.Touched:Connect(function()
	game.ReplicatedStorage.WorldEvents.BoatShopEvent1:FireClient()
end)

p.TouchEnded:Connect(function()
	game.ReplicatedStorage.WorldEvents.BoatShopEvent2:FireClient()
end)

I don't understand what I did wrong, I was told I could fire remote events from the server to the client. I attempted this, and can't find the error.

1 comment

0

This should most likely be a local script in which case you’d want OnClientEvent, but what is the function here? Who’s doing the touch? Where is the GUI stored?

1 answer

✓ Accepted answer

When you use :FireClient() from a server script, you need to define what player the server is gonna fire to in the arguments. If you dont, the server doesn't actually know what client to fire to and returns nil. I think you want to fire to the player that touched the brick, so you'd use :GetPlayerFromCharacter() to get the player.

local p = script.Parent

p.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then 
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)	
		if player then 
	    	game.ReplicatedStorage.WorldEvents.BoatShopEvent1:FireClient(player)
		end
	end
end)

-- I removed the TouchEnded event, since i really didnt think you wanted to fire twice. 

1 comment

0

Greatly Appreciated!!!

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