Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make it so that when a player touches a brick it only becomes transparent on there screen?

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)

2 comments

0

Put that script into a local script

2 answers

✓ Accepted answer

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.

6 comments

0

I used it but when i touched the brick another random brick diaapeared, and then i tryed it again without modyfiying anything and the character was all diffrent

0

You're right, I accidentally made it so that the part that touches the block turns invisible, not the block. Try the edited version.

0

It works so that the part becomes invisible but it can still be seen going invisible on both screens. Do you know why?

0

Make sure filtering enabled, a property of workspace, is on

0

Also make sure that it is a local script and that there are no other blocks named "EEE."

0

It still doesnt work, idk why.

This discussion is preserved as it was. New answers, comments, and votes are closed.