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 2 years ago
Edited 2 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 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 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:

local part -- location of your part in your game.
local transparent_part -- location of your part you want transparent

local Players = game:GetService('Players)
local plr = Players.LocalPlayer -- our client(player)

local transparency = 1 -- the number of transparency you want the part to get

part.Touched:Connect(function(hit)
 if hit.Parent:FindFirstChild('Humanoid') then -- verifies if hit's parent has 'Humanoid' as a children.
   if Players:GetPlayerFromCharacter(hit.Parent) == plr then -- verifies if the player that touched the part is our client.
      transparent_part.Transparency = transparency -- sets transparency to part
   end
 end
end)

Ad
Log in to vote
0
Answered by
Xeqro 20
2 years ago
Edited 2 years ago
local Players = game:GetService("Players")

local Part1 = workspace.Part1
local Part2 = workspace.Part2

Part1.Touched:Connect(function(Hit)
    local Player = Players:GetPlayerFromCharacter(Hit.Parent)

    if Player then
        if Player ~= Players.LocalPlayer then
            -- Someone touched the brick, but not me!

            Part2.Transparency = 1
        end
    end
end)

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 — 2y
0
Alright Xeqro 20 — 2y
0
where do i put the localscript? if i put it in a brick it usually doesn't work zenfurious6 7 — 2y

Answer this question