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

How to make a part collision off for a spicefic person script ?

Asked by 1 year ago

So like I’m trying to make a script where you say pass or enroll (user) so like :pass blahblah123 and it make this collision of for that part

0
Use collision groups RainDroutz 23 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

You can use LocalScripts (Client Scripts) and RemoteEvents. LocalScript runs a code only for the Client (you/LocalPlayer/the computer being used).

You may be asking: why are we gonna use Remote Events? If you're checking if a player typed a command, you will use the Server so that everyone can experience the command (and to avoid hacks). But how can we communicate with the Client? That's where RemoteEvents come in. They can send data from Server to Client and vice versa.

First, create a RemoteEvent in ReplicatedStorage and name it "PassPlayer". Next, create a script in ServerScriptService:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PassPlayer = ReplicatedStorage.PassPlayer -- the RemoteEvent
local passCommand = ":pass"

local function onJoin(player)
    player.Chatted:Connect(function(message) -- when player chats
        local arguments = message:split(" ") -- splitting the message by spaces

        local command = arguments[1]
        local targetName = arguments[2]

        if (command:lower() == passCommand) and (targetName ~= nil) then -- if player used the command and put a player's username
            for _, otherPlayer in ipairs(Players:GetPlayers()) do
                if otherPlayer.Name:lower():find(targetName:lower()) then -- if a name of a player matched the targetName
                    PassPlayer:FireClient(otherPlayer) -- fires to the client of the otherPlayer
                end
            end
        end
    end)
end

Player.PlayerAdded:Connect(onJoin)
for _, player in ipairs(Players:GetPlayers()) do
    coroutine.wrap(onJoin)(player)
end

Lastly, create a local script in StarterPlayerScripts (inside StarterPlayer):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PassPlayer = ReplicatedStorage:WaitForChild("PassPlayer") -- the RemoteEvent

local Door = workspace:WaitForChild("Door") -- for example, we have a part named "Door" in workspace

PassPlayer.OnClientEvent:Connect(function()
    Door.CanCollide = false
end)
0
Bit overengineered - you simply could've given them a solution such as adding the character to a collision group which doesn't collide with one of the door. wf_sh 15 — 1y
Ad

Answer this question