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

How do I make a script that when a player steps on a part it disappears? [closed]

Asked by 4 years ago

So let’s say a player steps on a part, it will disappear, but for other players it should look like no change was made until they step on the part?

0
Run the code in a LocalScript, only the player who stepped on the Part will see the change. Azarth 3141 — 4y
0
where do I put the local script? clopherite 4 — 4y

Closed as Not Constructive by hiimgoodpack and WideSteal321

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

3 answers

Log in to vote
0
Answered by 4 years ago

Code in a LocalScript runs purely on the client, which we can take advantage of here to do something that won't affect every other player's script.

Inside a Part is an Event called Touched, which when receives the signal that something has touched it will invoke any functions connected to it through the Connect method.

The Connect method takes a function, which will be invoked with whatever hit the part.

local Part = workspace:WaitForChild("PartNameHere")

Part.Touched:Connect(function(Hit) -- This is the hit argument that will be passed to our function.
    if Hit.Parent:FindFirstChild("Humanoid") then
        Part.Visible = false
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago
-- Local script & make sure filtering enabled is on.
local part = script.Parent --Part location here. eg. workspace.Part
part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- Checks if hit is a player.
        part:Destroy() -- You can use part.Transparency, but since you said 'disappear', I'm assuming you want to remove it.
    end
end)
Log in to vote
0
Answered by
Sulu710 142
4 years ago

The only problem with the other two answers ^^ is the script will run when any player touches the part, not just when that player touches it. Try using this script:

local Players = game:GetService("Players")
player = Players.LocalPlayer -- This is the player this script currently applies to

local Part = workspace:WaitForChild("Part") -- Reference the part you want to disappear here

Part.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Name = player.Name then -- This will check that  1. It is a player's character that hit the part  2. It is the user's character so the part will only disappear for them if they're the one to touch it
        Part.Visible = false -- Makes the part invisible
    end
end)

I hope this helps!

0
Where do I put the local script in the explorer? clopherite 4 — 4y