Script does not work

Hello developers. Basically script must log player’s name when player touch part but it won’t for some reason.
Script:

local first = nil
local second = nil
local third = nil
local fourth = nil
local cooldown = false

local queepart = script.Parent

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name == not second and not third and not fourth then
				cooldown = true
				workspace.Endless1:Fire()
				if first == nil then
					first = hit.Parent.Name
					print("first logged in")
					hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name == not first and not third and not fourth then
				cooldown = true
				workspace.Endless1:Fire()
				if second == nil then
					second = hit.Parent.Name
					print("second logged in")
					hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name == not first and not second and not fourth then
				cooldown = true
				workspace.Endless1:Fire()
				if third == nil then
					third = hit.Parent.Name
					print("third logged in")
					hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name == not second and not third and not first then
				cooldown = true
				workspace.Endless1:Fire()
				if fourth == nil then
					fourth = hit.Parent.Name
					print("fourth logged in")
					hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

How do I fix it?

edit: basically if i make script for each local (first second third fourth) i think that would work but I won’t use bindable event

Is that a local script or Script ?
is a touched event? (sorry im new to roblox dev forum)

No touch is function, it’s a script. There no problem you’re new

What is the error line ?
İf send error line, i help you

Did you put that Script im Roblox Default Part? If yes I Don’t know how to fix (because i’ve never coded)

hit.Parent:FindFirstChild(“Humanoid”) to game.Players:GetPlayerFromCharacter(hit.Parent) change.

there is no error line, i will try that later. Thanks

I’m slightly confused to what you’re trying to achieve, could you explain?

sorry if you’re talking About me because i dont speak English but i can speak a little bit

basically script worked before i add “if hit.Parent.Name = not second” and other stuff
i think there’s error, please read description

Give me a minute, I’m going to play around with your code and try to make it work.

local first = nil
local second = nil
local third = nil
local fourth = nil
local cooldown = false

local queepart = script.Parent

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			if game.Players:GetPlayerFromCharacter(hit.Parent).Name == not second and not third and not fourth then
				cooldown = true
				workspace.Endless1:Fire()
				if first == nil then
					first = game.Players:GetPlayerFromCharacter(hit.Parent).Name
					print("first logged in")
					game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			if game.Players:GetPlayerFromCharacter(hit.Parent).Name == not first and not third and not fourth then
				cooldown = true
				workspace.Endless1:Fire()
				if second == nil then
					second = game.Players:GetPlayerFromCharacter(hit.Parent).Name
					print("second logged in")
					game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			if game.Players:GetPlayerFromCharacter(hit.Parent).Name == not first and not second and not fourth then
				cooldown = true
				workspace.Endless1:Fire()
				if third == nil then
					third = game.Players:GetPlayerFromCharacter(hit.Parent).Name
					print("third logged in")
					game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

if cooldown == false then
	queepart.Touched:Connect(function(hit)
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			if game.Players:GetPlayerFromCharacter(hit.Parent).Name == not second and not third and not first then
				cooldown = true
				workspace.Endless1:Fire()
				if fourth == nil then
					fourth = game.Players:GetPlayerFromCharacter(hit.Parent).Name
					print("fourth logged in")
					game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
					wait(1)
					cooldown = false
				end
			end
		end
	end)
end

respect, i’ll test it right now and tell you later :).

still not work, well,
maybe there’s error: if game.Players:GetPlayerFromCharacter(hit.Parent).Name == not second and not third and not fourth then

why not use a table instead of 4 independent variables?

I believe I have got it to achieve what you wanted, here is the code:

local first = nil
local second = nil
local third = nil
local fourth = nil
local cooldown = false

local queepart = script.Parent


queepart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and cooldown == false then
		if hit.Parent.Name ~= second and hit.Parent.Name ~= third and hit.Parent.Name ~= fourth and first == nil then
			cooldown = true
			workspace.Endless1:Fire()
			first = hit.Parent.Name
			print("first logged in")
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
			wait(1)
			cooldown = false
		end
	end
end)

queepart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and cooldown == false then
		if hit.Parent.Name ~= first and hit.Parent.Name ~= third and hit.Parent.Name ~= fourth and second == nil and first ~= nil then
			cooldown = true
			workspace.Endless1:Fire()
			second = hit.Parent.Name
			print("second logged in")
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
			wait(1)
			cooldown = false
		end
	end
end)


queepart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")and  cooldown == false then
		if hit.Parent.Name == hit.Parent.Name ~= first and hit.Parent.Name ~= second and hit.Parent.Name ~= fourth and third == nil and second ~= nil then
			cooldown = true
			workspace.Endless1:Fire()
			third = hit.Parent.Name
			print("third logged in")
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
			wait(1)
			cooldown = false
		end
	end
end)


queepart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and cooldown == false then
		if hit.Parent.Name ~= second and hit.Parent.Name ~= third and hit.Parent.Name ~= first and fourth == nil and third ~= nil then
			cooldown = true
			workspace.Endless1:Fire()
			fourth = hit.Parent.Name
			print("fourth logged in")
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-42.371, 48.757, 0.76)
			wait(1)
			cooldown = false
		end
	end
end)

ill test it and tell you later work it or not

yay! thank you alot dude, it worked :smiley:

in addition to this, the script can probably just be shortened to this

local part = script.Parent
local logged = {}

part.Touched:Connect(function(hit)
	local model = hit:FindFirstAncestorOfClass("Model")
	local plr = game:GetService("Players"):GetPlayerFromCharacter(model)
	
	if model and plr and not table.find(logged,plr.Name) and #logged < 4 then
		logged[#logged + 1] = plr.Name
		model:PivotTo(CFrame.new(-42.371, 48.757, 0.76))
        workspace.Endless1:Fire()
	end
end)

its cleaner to read and does basically the same thing but with more flexibility since its a table