Help with local event

I don’t know much about Local Script and Remove Event, and I need help to make a script work only for the player who touched a brick.

local Brick = script.Parent

Brick.Touched:Connect(function(hit)
    Brick.CanCollide = false
    Brick.Transparency = 1
end)

How can I make the transparency and collision of the brick be affected only for the player who touches it?

I’ve done this before but with a button that opens a door for only the person who opens it. I used a normal script for when the player touches the button which fires a RemoteEvent to a local script so the event only appears on a certain player’s screen.

1 Like

since its happening only to the client you might aswell just make it happen all on the client since the touched event still works on the client, and if a player is laggy if its all on the client it will run smoothly since it doesnt have to send anything from the server to the client

2 Likes

check if the hit variable is an instance belonging to the host player

the way i usually do it is with :GetPlayerFromCharacter(), probably not the best way, use whatever works for you
ex:

local Brick = script.Parent

Brick.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) == game.Players.LocalPlayer then -- added this line
        Brick.CanCollide = false
        Brick.Transparency = 1
    end -- added this line
end)

(if hit is the the limb of a character, its parent would be the character of the host player)
((this would be in a localscript btw, or a script with RunContext set to the client))

2 Likes