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 4 years ago
Edited by Ziffixture 4 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:

 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 answers

Log in to vote
0
Answered by 4 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:

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);
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

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 — 4y
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 — 4y
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 — 4y
0
Make sure filtering enabled, a property of workspace, is on GriffthouBiff 147 — 4y
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 — 4y
0
It still doesnt work, idk why. YourAverageMyth 45 — 4y

Answer this question