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

How do I get a localpart to disappear when player touches a switch?

I have got a localpart that loads into my game when the player connects, I have used the script off of the wiki page to do this:

local container = Workspace:FindFirstChild("LocalBin")
if not container then
    container = Instance.new("Camera")
    container.Name = "LocalBin"
    container.Parent = Workspace
end
 
local platform = Instance.new("playerdoor")
platform.CFrame = platform.CFrame * CFrame.new(23, 3.5, -119.5)
platform.Anchored = true
platform.Size = Vector3.new(2, 7, 7)
 
platform.Parent = container

and it worked perfectly. The localpart shows up for the client just as I wanted, however I tried to add a switch that the player could touch in order to make the localpart disappear when the player completes a task, but it does not run the script when touched, and no error comes into the output either...

This is the script I placed into the switch block

function touch()
		game.Workspace.LocalBin.playerdoor.Transparency = 1
end

script.Parent.Touched:connect(touch)

2 comments

0

playerdoor is not a valid Instance. Line 8.

0

Yees ignore that part, I changed the playerdoor's back to 'Part', and the first script works perfectly well, I'm just still struggling to get the touch switch to communicate with the localpart...

1 answer

✓ Accepted answer

you could have the lever script alert the local script with events. This might not be the most efficient way, but here's an example:

--script

local event = Instance.new("RemoteEvent",game.ReplicatedStorage)
event.Name = "lever touched"

script.Parent.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		event:FireClient(player,player)
	end
end)
--local script

local container = workspace:FindFirstChild("LocalBin")
if not container then
    container = Instance.new("Camera")
    container.Name = "LocalBin"
    container.Parent = workspace
end
local platform = Instance.new("Part")
platform.CFrame = platform.CFrame * CFrame.new(23, 3.5, -119.5)
platform.Anchored = true
platform.Size = Vector3.new(2, 7, 7)

platform.Parent = container

local event = game.ReplicatedStorage:WaitForChild("lever touched")

event.OnClientEvent:connect(function(p)
	container.playerdoor.Transparency = 1
end)

--This isn't tested, so let me know if you encounter any problems with it.

1 comment

0

This actually worked... Thank you so much! I spent about 4 hours yesterday trying everything I could, it was horrible

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