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