Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with Cloning block to certain characters heads?

I have a block the goes over every characters head but I want certain players to have the "DisplayInfo[Tester]" one.

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		--plr.Character:WaitForChild("Health"):Destroy()
		if char.Name ~= 'NAMEHERE' or char.Name ~= 'NAMEHERE2' then
			local Part = game.ReplicatedStorage:WaitForChild("DisplayInfo"):Clone()
			Part.Parent = plr.Character
	
			Part.CFrame = char.Head.CFrame
			Part.Anchored = false
			Part.CanCollide = false
					
			local Weld = Instance.new("Weld", Part)
			Weld.Part0 = char.Head
			Weld.Part1 = Part
			Weld.C1 = CFrame.new(0,1,0) * CFrame.new(0,-5,0)
			
		else
			
			local Part = game.ReplicatedStorage:WaitForChild("DisplayInfo[Tester]"):Clone()
			Part.Parent = plr.Character
	
			Part.CFrame = char.Head.CFrame
			Part.Anchored = false
			Part.CanCollide = false
					
			local Weld = Instance.new("Weld", Part)
			Weld.Part0 = char.Head
			Weld.Part1 = Part
			Weld.C1 = CFrame.new(0,1,0) * CFrame.new(0,-5,0)
			
		
		end		
	end)
end)

1 answer

You have replicated a lot of code just to do the same thing. I would highly recommend that you use the players user id as a player can change their name.

Quick example:-

-- the tester list 
local plrList = {
	[some id num] = true
}

-- cached clones
local displayInfo = game.ReplicatedStorage:WaitForChild("DisplayInfo"):Clone()
-- why are you using replicated storage, does the client need this as well?
local displayInfoTester = game.ReplicatedStorage:WaitForChild("DisplayInfo[Tester]"):Clone()

-- small function to pass back the display we need instead of duplicating the whole code
local function isTester(plrId)
	-- method 1
	--return plrList[plrId] and displayInfoTester:Clone() or displayInfo:Clone()
	
	-- method 2
	if plrList[plrId] then return displayInfoTester:Clone() else return displayInfo:Clone() end
end

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
		local charHead = char:WaitForChild('Head')
		-- check the player
		local Part = isTester(plr.UserId)
		
		Part.Parent = char
		Part.CFrame = charHead.CFrame
		Part.Anchored = false -- you could just set these in the cloned part
		Part.CanCollide = false
		
		local Weld = Instance.new("Weld", Part)
		Weld.Part0 = charHead
		Weld.Part1 = Part
		Weld.C1 = CFrame.new(0,1,0) * CFrame.new(0,-5,0)
	end)
end)

I hope this helps, please comment if you do not understand how / why this code works.

This discussion is preserved as it was. New answers, comments, and votes are closed.