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

How to make a script make a function appear only to the player who touched it?

Asked by 3 years ago
Edited 3 years ago

basically what i wanna do is that when you touch a part, another part gets set to transparent but everyone sees that part as transparent instead of just that player, that's the problem.

0
i edited my answer Xeqro 20 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This is simple and easy to do.

First create a local script, you can put this script inside anywhere that can work(I'll put it inside StarterPlayerScripts).

Inside the local script type:

01local part -- location of your part in your game.
02local transparent_part -- location of your part you want transparent
03 
04local Players = game:GetService('Players)
05local plr = Players.LocalPlayer -- our client(player)
06 
07local transparency = 1 -- the number of transparency you want the part to get
08 
09part.Touched:Connect(function(hit)
10 if hit.Parent:FindFirstChild('Humanoid') then -- verifies if hit's parent has 'Humanoid' as a children.
11   if Players:GetPlayerFromCharacter(hit.Parent) == plr then -- verifies if the player that touched the part is our client.
12      transparent_part.Transparency = transparency -- sets transparency to part
13   end
14 end
15end)
Ad
Log in to vote
0
Answered by
Xeqro 20
3 years ago
Edited 3 years ago
01local Players = game:GetService("Players")
02 
03local Part1 = workspace.Part1
04local Part2 = workspace.Part2
05 
06Part1.Touched:Connect(function(Hit)
07    local Player = Players:GetPlayerFromCharacter(Hit.Parent)
08 
09    if Player then
10        if Player ~= Players.LocalPlayer then
11            -- Someone touched the brick, but not me!
12 
13            Part2.Transparency = 1
14        end
15    end
16end)

It's pretty self explanatory, also this is still a LocalScript, I'm just kind of confused on your question

0
sorry this was not what i meant. i meant that IF the player touched the part, another part gets set to transparent but that part appears transparent to everybody else, and not the player. that's what i'm trying to do. zenfurious6 7 — 3y
0
Alright Xeqro 20 — 3y
0
where do i put the localscript? if i put it in a brick it usually doesn't work zenfurious6 7 — 3y

Answer this question