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

How do i make something collidable on only one client?

Asked by
CjayPlyz 643 Moderation Voter
6 years ago

How do i make something collidable on only one client?

1 answer

Log in to vote
1
Answered by
oreoollie 649 Moderation Voter
6 years ago
Edited 6 years ago

This can be done by turning on FilteringEnabled and possibly using RemoteEvents, depending on what you're trying to do. If you're trying to make an owner only door or something then it can be done without remote events. That is the LocalScript below.

local OwnerId = 0
local Part = workspace.Part

if game.Players.LocalPlayer.UserId == OwnerId then
    Part.CanCollide = false
end

Things get a little more complex if you're looking to make a door that the server tells the client to open. This requires putting a RemoteEvent in ReplicatedStorage. I would recommend naming it OpenDoor or something similar. The server will run the below code to tell the client to manipulate the door.

game:GetService("ReplicatedStorage").OpenDoor.FireClient(playerInstance, true) -- Opens it
game:GetService("ReplicatedStorage").OpenDoor.FireClient(playerInstance, false)

The client would use the LocalScript below to react to the server's request:

function ManipulateDoor(f)
    local p = workspace.Part
    if f == true then
        p.CanCollide = false
    elseif f == false then
        p.CanCollide = true
    end
end

game:GetService("ReplicatedStorage").OnClientEvent(ManipulateDoor)

I hope my answer was able to solve your problem. If it did, please remember to mark it as correct!

0
thanks CjayPlyz 643 — 6y
0
No problem. oreoollie 649 — 6y
Ad

Answer this question