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?
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?
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?
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