Im trying to get it so that when a player touches a part a part becomes transparrent only on there screen, I have the code but it only works with a normal script. Does anyone know how to make it work with local script or just make it so that the player who touched sees the part go invisible? My code:
local EEE = game.Workspace.EEE script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) game.Workspace.EEE.Transparency = 1 wait(1) game.Workspace.EEE.Transparency = 0 end)
Griff was on the right track with his answer, but he didn't add a very important part, that part being a check that makes sure it was YOUR character that touches the part. Because right now, if that part gets touched at all, it'll make it invisible for everyone, because everyone's localscript is detecting it being touched.
Quick fix for that would be as follows:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local part = workspace:WaitForChild("EEE") local function OnTouched(part) if part:IsDescendantOf(character) and workspace:FindFirstChild("EEE") then -- makes sure that EEE exists and that the part that touched EEE is indeed the local player workspace["EEE"].Transparency = 1; end end part.Touched:Connect(OnTouched);
The code below should be in a localscript in StarterPlayerScripts
local function OnTouched(part) workspace:WaitForChild("EEE").Transparency = 1; end workspace:WaitForChild("EEE").Touched:Connect(OnTouched); -- I highly recommend always using :WaitForChild when searching for the child of anything
The reason this works is because this localscript will only trigger for the client that touched the brick; thus the server does not notice this change. Local scripts will always act like this, being independent from the server. Good luck with your game.