Scripting Support

Hey developers, I have made a model that falls and fades when a person touches it, but I don’t want everyone to see it only the local player that sees it, how would I do that.
The script is:

local topPart = script.Parent
local parts = {}
for _, child in ipairs(model:GetChildren()) do
	if child:IsA("BasePart") then
		table.insert(parts, child)
	end
end
local busy = false

-- config
local goDown = 10 -- how much studs to move platform down
local duration = 1 -- how long it takes to move down in seconds
----------

local iterations = duration * 30
local step = goDown / iterations

topPart.Touched:Connect(function()
	if busy then return end
	busy = true
	for i = 0, iterations do
		model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0, -step, 0))
		if parts == {} then wait() continue end
		for _, part in ipairs(parts) do
			part.Transparency = math.min(part.Transparency + 1/iterations, 1)
		end
		if i > iterations / 2 then
			for _, part in ipairs(parts) do
				part.CanCollide = false
			end
		end
		wait()
	end
	wait(1)
	for i = 0, iterations do
		model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0, step, 0))
		if parts == {} then wait() continue end
		for _, part in ipairs(parts) do
			part.Transparency = math.max(part.Transparency - 1/iterations, 0)
		end
		if i > iterations / 2 then
			for _, part in ipairs(parts) do
				part.CanCollide = true
			end
		end
		wait()
	end
	busy = false
end)

Use remote events and make the part that hides the object a local script

I think you can just add a localscript in the part and put your current code in that localscript then it would only play for the localplayer - make sure you check if the hit part belongs to the localplayer though (ie you dont want to run it when a different player touches it)

I think I accomplished it here (it can be done better) but im like 80% sure it works so ye

local players = game.Players
local localPlayer = players.LocalPlayer

local topPart = script.Parent
local parts = {}
for _, child in ipairs(model:GetChildren()) do
	if child:IsA("BasePart") then
		table.insert(parts, child)
	end
end
local busy = false

-- config
local goDown = 10 -- how much studs to move platform down
local duration = 1 -- how long it takes to move down in seconds
----------

local iterations = duration * 30
local step = goDown / iterations

topPart.Touched:Connect(function(hit)
	-- check if the hit part belongs to a player, then see if that player is the localplayer
	local hum = hit.Parent:FindFirstChildOfClass("Humanoid") or hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
	local char = hum and hum.Parent
	local plr = char and players:FindFirstChild(char.Name)
	if plr ~= localPlayer then return end
	
	if busy then return end
	busy = true
	for i = 0, iterations do
		model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0, -step, 0))
		if parts == {} then wait() continue end
		for _, part in ipairs(parts) do
			part.Transparency = math.min(part.Transparency + 1/iterations, 1)
		end
		if i > iterations / 2 then
			for _, part in ipairs(parts) do
				part.CanCollide = false
			end
		end
		wait()
	end
	wait(1)
	for i = 0, iterations do
		model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0, step, 0))
		if parts == {} then wait() continue end
		for _, part in ipairs(parts) do
			part.Transparency = math.max(part.Transparency - 1/iterations, 0)
		end
		if i > iterations / 2 then
			for _, part in ipairs(parts) do
				part.CanCollide = true
			end
		end
		wait()
	end
	busy = false
end)

Alright I will try if it works and I will update you on if it fixed the problem or not!
Thanks!

It does not work, now the part just doesn’t fall.

Putting it in a local script should work, but just copying it and pasting the code over to a local does not work, your going to need to change it’s functions and such.

local Humanoid = game.Players.LocalPlayer.Character.Humanoid

Humanoid.Touched:Connect(function(model)
if model.Name == "(Whatever the model name is)" then
--- your code
end
end)

^^ just an example of what I would do. You can try to see if it helps.

Oh, okay
I will try and Update you on the progress.
Meanwhile you can try my game:

https://www.roblox.com/games/8483406324/Obby

(I made it on my alt)

Thanks!

  • Alt_youlzr