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

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

Asked by 5 years ago
Edited by Ziffixture 5 years ago

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:

1local EEE = game.Workspace.EEE
2script.Parent.Touched:Connect(function(hit)
3 local player = game.Players:GetPlayerFromCharacter(hit.Parent)
4game.Workspace.EEE.Transparency = 1
5wait(1)
6game.Workspace.EEE.Transparency = 0
7 
8  end)

2 answers

Log in to vote
0
Answered by 5 years ago

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:

01local player = game.Players.LocalPlayer
02local character = player.Character or player.CharacterAdded:wait()
03 
04local part = workspace:WaitForChild("EEE")
05 
06local function OnTouched(part)
07    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
08        workspace["EEE"].Transparency = 1;
09    end
10end
11 
12part.Touched:Connect(OnTouched);
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The code below should be in a localscript in StarterPlayerScripts

1local function OnTouched(part)
2    workspace:WaitForChild("EEE").Transparency = 1;
3end
4 
5workspace: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.

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 YourAverageMyth 45 — 5y
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. GriffthouBiff 147 — 5y
0
It works so that the part becomes invisible but it can still be seen going invisible on both screens. Do you know why? YourAverageMyth 45 — 5y
0
Make sure filtering enabled, a property of workspace, is on GriffthouBiff 147 — 5y
View all comments (2 more)
0
Also make sure that it is a local script and that there are no other blocks named "EEE." PadmeOragana 78 — 5y
0
It still doesnt work, idk why. YourAverageMyth 45 — 5y

Answer this question