2 Player Touch Baseplate: Detection Problems

Hey everyone,

Again. the first one that touches the part is the one that is detected by the touch event - without the player itself

Again. the first one that touches the part is the one that is detected by the touch event - without the player itself with the palyer itself I mean the player.character

so for example when the first one of 100 hits the part it will just get the first one.
but let it us say the first one is the humanoid, then it the touchevent even wont hit anything

this above is the best explanation you can get!!!

I have a big problem and that is: I want make a detection but just for 2 players. me and the humanoid I hitted and when the firstplayer gets hit - without me - then the Gui pops on his Screen.

But with my script I have a big issue and that is, that my touch event detects me and also it does detect me as first humanoidrootpart what it shouldnt do.

Here a video to visualize everything better:

https://streamable.com/c2fhmm

if you still didnt understand what happen in the video let me explain you: The Player2 gets the Gui and that shoudnt happen before he doesnt touch the part, it seems like the Player1 activate the touchevent, and that is a big issue we have to fix.

local base =  game.Workspace:WaitForChild("Baseplate")
local connection

local touched = false 

game.Players.PlayerAdded:Connect(function(player)
	connection = base.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and touched == false 
			and hit ~= player.Character and not hit:IsDescendantOf(player.character)then
			touched = true
			local hitted = hit.Parent
			local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
			local HumanoidNPC = hit.Parent:FindFirstChild("Humanoid")
			local plr2 = game.Players:GetPlayerFromCharacter(hitted)
			local EHumanoidP = HumanoidRootPart.Position

			local Clone1 = script.AttackCollection:Clone()
			local Clone2 = script.AttackCollection:Clone()
			Clone1.Parent = player.PlayerGui
			Clone2.Parent = plr2.PlayerGui
			
			Clone2.Enabled = true
			Clone1.Enabled = true
			
			local Player = hit.Parent
			connection:Disconnect()
		end
	end)	
end)
1 Like

Got Discord, Spy#0005, I will explain u something

why you create

baseplate.Touched

when player added? it sounds weird to me

it is just for testing nothing more

I sended a friendrequest you can accept it why do you want explain me something

why hit ~= player.Character? coz it will return player character rig parts

You’re firing the connection twice, so it’s being replicated to both players when they touch the baseplate

Also did you mean to only Enable 1 Clone?

game.Players.PlayerAdded:Connect(function(player) — what is the point of this? .Touched:() is already an event that fires, there’s no need for the PlayerAdded event.

no you didnt understand my explanation!

Remove that part, it’s giving it to the player as soon as they join.

noo I need that cuz it should also clone a part on my desct and also it does not giving the player as soon as they join just when the touch gets active

Then you need to make it another function — putting 2 events in one function is horrible practice and can result in bugs.

1 Like
local touches= 0
local plrs= {}
local gui = script:WaitForChild("ScreenGui")
script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		if touches >= 2 then return end
		if table.find(plrs,plr) then return end
		table.insert(plrs,plr)
		touches=touches+1
		local c=gui:Clone() c.Parent = plr.PlayerGui
		
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if table.find(plrs,plr) then
		table.remove(plrs,table.find(plrs,plr))
		touches=touches-1
	end
end)

Again. the first one that touches the part is the one that is detected by the touch event - without the player itself with the palyer itself I mean the player.character

so for example when the first one of 100 player hits the part it will just get the first one.
but let it us say the first one is the player.Character, then the touchevent even wont hit the player.character just when it gets the first character

this above is the best explanation you can get!!!