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?
COMMUNITY QUESTION
How do I make a script that when a player steps on a part it disappears?
3 answers
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)
-- 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)
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!
1 comment
0
Where do I put the local script in the explorer?
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Run the code in a LocalScript, only the player who stepped on the Part will see the change.
where do I put the local script?