Locally making a part appear while a player is touching it?

I am trying to make a part appear only while a player is touching it, and then when they no longer are touching it, it will return it to 1 transparency locally.

So far, I’ve had the beginning part of the script only work when it’s not a local script. I’m not sure if I’m missing something?

local myPart = script.Parent
local player = game.Players.LocalPlayer

-- Set initial transparency
myPart.Transparency = 1

-- Function to handle when the part is touched
local function onTouch()
	-- Change part transparency to 0 when touched
	myPart.Transparency = 0
end

-- Function to handle when the part is no longer touched
local function onUnTouch()
	-- Change part transparency to 1 when not touched
	myPart.Transparency = 1
end

-- Connect the onTouch function to the Touched event of the part
myPart.Touched:Connect(onTouch)

-- Connect the onUnTouch function to the TouchEnded event of the part
myPart.TouchEnded:Connect(onUnTouch)
1 Like

Localscripts don’t run when they are inside of workspace, they have to be in a couple of specific locations to run.
Either; StarterPack, StarterGui, StarterPlayerScripts, StarterCharacterScripts, or ReplicatedFirst.

You can just change the RunContext of a normal script to be on the client though, and then it should be able to run anywhere.
image

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.