Changing the CanCollide property locally

Hello.

I am currently trying to create a part where you can change the CanCollide properties locally so only the person that scans a key card/ticket can walk through that part.

I am currently using a method with ServerScripts but sadly by doing that it gives everybody without a ticket or a key card access to the staff area/vip rooms.

This is my ServerScript

script.Parent.TicketScanner.Part.Touched:Connect(function(hitturn)
	if hitturn.Name == "ValidTicket" then
		script.Parent.Blocker.CanCollide = false
		wait(5)
		script.Parent.Blocker.CanCollide = true
	end
end)

It’s a very basic script but it works (not locally)

LocalScripts don’t work since you can’t really change properties with a LocalScript at least when I tried.

Appreciate any help.

2 Likes
1. Create RemoteEvent called "CheckTicket" in ReplicatedStorage.

image

2. Replace the ServerScript with this, but keep the script in the same place.
local Event = game:GetService("ReplicatedStorage"):WaitForChild("CheckTicket") -- Make RemoteEvent in ReplicatedStorage

script.Parent.TicketScanner.Part.Touched:Connect(function(hitturn)
	for i,v in pairs(game.Players:GetPlayers()) do
		if hitturn.Name == "ValidTicket" then
			if hitturn:IsDescendantOf(v.Character) then
				Event:FireClient(v,script.Parent.Blocker)
			end
		end
	end
end)
3. Place a LocalScript in StarterPlayer > StarterCharacterScripts, and put this in it.
local Event = game.ReplicatedStorage:WaitForChild("CheckTicket")
local Debounce = false

Event.OnClientEvent:Connect(function(Blocker)
	if Debounce == false then
		Debounce = true
		Blocker.CanCollide = false
		wait(5)
		Blocker.CanCollide = true
		Debounce = true
	end
end)
1 Like

Just tested it and it worked perfectly, Thank you.