RemoteEvent firing for everyone, but it shouldn't

Hello. I am trying to make those kind of infection games (Manly Infection, Noob Infection etc.) and I ran into a problem: When a player’s character touches the goo, the other players in the server are transformed into a monster too.

Local Script in StarterCharacterScripts
local char = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local hrp = char.HumanoidRootPart
local goos = workspace.Goos
local GreenGoos = goos.GreenGoos
local YellowGoos = goos.YellowGoos
local BlackGoos = goos.BlackGoos
local WhiteGoos = goos.WhiteGoos
local rs = game.ReplicatedStorage
local infected = false
local color = char.Torso.BrickColor

for _, v in pairs(YellowGoos:GetChildren()) do
	if v.Name == "YellowGoo" then
		v.Touched:Connect(function(hit)
			if infected == false then
				rs.YellowGoo:FireServer(player)
				infected = true
			else
				
			end
		end)
	end
end

The script in ServerScriptService just takes the RemoteEvent and does the effects.
Any help?

In the :FireServer event you don’t need the first parameter.

I used that so it could take the player, because on the server I need to get the player’s character, you know, for effects

You don’t need to send the Player argument when firing server because this argument will be already pass in automatically when its onServerEvent

Also if you want the character just do Plr.Character you don’t have to send the character etc

1 Like

You don’t have any hit verification judging by the fact this is a local script, change your tocuhed event for the YellowGoo to this

v.Touched:Connect(function(hit)
	if not hit:IsDescendantOf(char) then return end
	if not infected then
		rs.YellowGoo:FireServer()
		infected = true
	end
end)

Also as others have stated, the game automatically passes in the player who fired the event

Everyone has the touched event connected for the goo, so if one person touches it, everyoen wil lbe affected, you need to verify who touches it. Also why is this in a local script?

1 Like

Yeah, so on the server you can do this:

local Event = --- Event here

Event.OnServerEvent:Connect(function(player)
   local Character = player.Character
end)

Everything removing the Event:FireServer(player) doesn’t work, let me try what @EmbatTheHybrid said

Why don’t you just transfer this to a ServerScript? It’ll work much easier.

Probably, but it will be hard for me to get if the lcoal player has touched the goo, since I am not a good programmer

Touched returns the part that hit the part, you can just do

local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

Where hit is the name of the returned argument

Actually, it should be relatively simple.

Part.Touched:Connect(function(Hit)
local Hum = Hit.Parent:FindFirstChild("Humanoid")
if Hum then
local Player = game.Players:GetPlayerFromCharacter(Hum.Parent)
end

This is in a local script because I wanted to transfer to the server who is touching the goo. How would I check who touched the goo? By checking hit.Parent.Name == local player?

So if I’m understanding you correctly, you want the Player to be seen by the server?

1 Like

OnServerEvent automatically sets the first parameter to be the player who fired the event, that’s how you get the player who has to be transformed.

But again,you’re better off converting thsi to work on regular scripts

1 Like

In that case, the code I’ve provided above would be fine. You can access the Player with :GetPlayerFromCharacter()

1 Like

Ok, I will do as you guys stated. Sadly for me which has to re-write the entire system but thats fine, i like working

EDIT: Idk which response I should put as solved

1 Like

If you need any help transferring this to a server script (or whatever your plan is), don’t be afraid to ask.

It shouldn’t be that difficult, you just need to verify the part that’s touching the goo is player, and if it is, do something.

Example

v.Touched:Connect(function(hit)
	local char = hit.Parent
	local plr = game:GetService("Players"):GetPlayerFromCharacter(char)
	if not plr then return end
	
	--Goo Code
end)

Where v is a goo part, all you really need to just transfer the code from the RemoteEvent into the touched event for the goos in a server script

1 Like