I attempted to make a part that only one player can touch, and no one else can take that one player's spot until he leaves the part.

Example (what i'm trying to make it look like); Auto Duels pads, Custom Duels pads.

I've been trying and researching for hours but I couldn't find a solution.. What's the problem?

I'm new to scripting and my knowledge is really low, if you could explain in a sample of code that would be appreciated!

 local Part = script.Parent
    local alreadyin =  {}
    local db = true
      
    Part.Touched:Connect(function(hit)
    	if not db then
    		return
    	end
    	db = false
    	if hit.Parent:FindFirstChild("Humanoid") then
    		local player = game.Players[hit.Parent.Name]
    		if alreadyin[1] == nil then
    			table.insert(alreadyin, player.Name)
    		end
    		for i,v in pairs(alreadyin) do
    			if v == player.Name then
    				Part.Color = Color3.fromRGB(0, 255, 255)
    				Part.TouchEnded:wait()
    				alreadyin[1] = nil
    				Part.Color = Color3.fromRGB(163, 162, 165)
    			end
    		end
    	end
    	db = true
    end)

1 comment

0

The way you are getting the player is really inefficient, consider using this much simpler method instead: local player = game.Players:GetPlayerFromCharacter(hit.Parent)