Table not working properly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to make people dissapear/appear on function call for the client

  1. What is the issue? Include screenshots / videos if possible!
    image
    The person dissapears, then when he appears he looks like this.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Nothing really, just can’t find the issue.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    Does anyone see the problem? Also im posting the full script and mabye you can tell me what can I improve?

local tweenService = game:GetService("TweenService")
local promptService = game:GetService("TweenService")
local plrService = game:GetService("Players")
local player = game.Players.LocalPlayer
local controls = require(player.PlayerScripts.PlayerModule):GetControls()
-- Objects

local plrCamera = workspace.Camera
local prompt = game.Workspace.spawnhouse.counter.man.Head.prompt.ProximityPrompt
--Hide players
local hiddenParts = {}
function hidePlayers()
	for i, plr in pairs(plrService:GetChildren()) do
		local plrChar = plr.Character
		for i, part in pairs(plrChar:GetChildren()) do
			if part:IsA("Part") or part:IsA("MeshPart") then
				part.Transparency = 1
				table.insert(hiddenParts,part)
			elseif part:IsA("Accessory") then
				part:FindFirstChild("Handle").Transparency = 1
				table.insert(hiddenParts,part)
			end
		end
	end
end
-- Show players
function showPlayers()
	for i, part in pairs(hiddenParts) do
		local index = table.find(hiddenParts,part)
		if part:IsA("Accessory") then
			part:FindFirstChild("Handle").Transparency = 0 
		else
			part.Transparency = 0
		end
		table.remove(hiddenParts,index)
	end
end
--Cutscene style

local duration = 3

local tweenInfo = TweenInfo.new(
	duration,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)

-- Cutscene zooms on NPC
local cutScenePart = script.Parent.cutSceneParts.cam1.CFrame

local function tween (loc1, loc2)
	plrCamera.CameraType = Enum.CameraType.Scriptable

	local tween = tweenService:Create(plrCamera, tweenInfo, {CFrame = loc2})
	controls:Disable()
	prompt.Enabled = false
	tween:Play()
	hidePlayers()
	wait(duration)
	
	
end

-- Event listeners

prompt.Triggered:Connect(function()
	tween(plrCamera.CFrame,cutScenePart)
end)

wait(5)
hidePlayers()
wait(5)
showPlayers()

Well, you aren’t checking if part.Name == "HumanoidRootPart", hence why that grey square is there. And, I think you should actually instead change the LocalTransparencyModifier of the item since you want the transparency to only show for the player.

So, with that in mind, I think the final script would be this:

function hidePlayers()
	for i, plr in pairs(plrService:GetChildren()) do
		local plrChar = plr.Character
		for i, part in pairs(plrChar:GetChildren()) do
			if (part:IsA("Part") or part:IsA("MeshPart")) and part.Name ~= "HumanoidRootPart" then
				part.LocalTransparencyModifier = 1
				table.insert(hiddenParts,part)
			elseif part:IsA("Accessory") then
				part:FindFirstChild("Handle").LocalTransparencyTransparency = 1
				table.insert(hiddenParts,part)
			end
		end
	end
end
-- Show players
function showPlayers()
	for i, part in pairs(hiddenParts) do
		-- local index = table.find(hiddenParts,part) <-- what's the reason for this if you're using pairs? commented but i'd mark it as unnecessary
		if part:IsA("Accessory") then
			part:FindFirstChild("Handle").LocalTransparencyModifier = 0 
		else
			part.LocalTransparencyModifier = 0
		end
		table.remove(hiddenParts,index)
	end
end

Does local transparency modifier make a difference if im using a local script?

Yes, it’ll only change the transparency for the client only.
And because you were getting the local player, which by way of doing that is only through a local script, then this should work within that script.

If you were to do it server-sided, it wouldn’t do anything.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.