Scripting improvement

Hello guys,

I made a barrier gate with animation but I would like to make it to go only 1 person at a time.

Here is a script:

local debounce = false
script.Parent.Touched:connect(function(p)
	if p.Parent.Name == "Ticket" and debounce == false then
        debounce = true
		script.Parent.Parent.DL.Motor.DesiredAngle = 1.5
		script.Parent.Parent.DR.Motor.DesiredAngle = 1.5
		wait(5)
		script.Parent.Parent.DL.Motor.DesiredAngle = 0
		script.Parent.Parent.DR.Motor.DesiredAngle = 0
		wait(5)
        debounce = false
	end
end)

So, what should I do like if someone bypasses and I would like to make person not glitching. When they tries, they should be respawned or put back and appearing the GUI not to glitch, etc.

Is this a local script or server script?

Normal script, not local. So, I should have a local script?

You want the bypass and checks to be done on the server. As a client can easily exploit the code on a local script.

Also, you can have the server handle the animations and whatever else needs to be done. Then, you can simply have the server switch a boolean to allow another user to bypass. The debounce can be used as the boolean to allow one person at a time.

Im not saying it should be a local script, just wanted to know.

1 Like

I was just explaining :slight_smile:

Oh Ok :slight_smile: 30 charsssssssssssssss

Oh, I just noticed another guy looks like you haha.

haha, loads of other people that look like me out there :slight_smile:

1 Like

Oh, hmm. I see, even like that they can still exploit right?

No, if the code is on a server script, they cannot exploit it. Only local scripts can be exploited. This is getting confusing. You two look like twins.

What should I do? Is that hard to script to make it only by 1 person?

script.Parent.Touched:connect(function(p)
    if (player has ticket and debounce == false) then
        debounce = true -- This will prevent multiple players with tickets to pass at once.
        -- Your player passing code here
        debounce = false -- Allow the next player to pass
    end
end)

You also have to check if the part that touched the gate belongs to a player character.

So, I have to add part brick and Humanoid?

Is the ticket a tool that the character holds?

Yes, the tool with a part named Handle.

Then yes, you can do the following:
if (p.Parent:FindFirstChild("Humanoid") and p.Parent:FindFirstChild("tickettoolname") and debounce == false)

That checks if the part that touched the gate deblongs to a player character, and if they have a ticket in their hand, and if no one is passing through the gate at the time they touched it.

So, wait I put script below the part handle that and humainoid then an part below of gate right?

I did put humanoid below part handle and that script.