Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
mrcool2 75
9 years ago

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)
0
playerdoor is not a valid Instance. Line 8. M39a9am3R 3210 — 9y
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... mrcool2 75 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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.

0
This actually worked... Thank you so much! I spent about 4 hours yesterday trying everything I could, it was horrible mrcool2 75 — 9y
Ad

Answer this question