So first we want a character limit and a character counter so we're going to define this.
local NeededCharacters = 10
local Characters = 0
Now that we know how much characters we need let's continue.
script.Parent.Touched:Connect(function(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
Here since we know that the players are have something named "Masked" inside of them so we are going to make sure it's not nil and it exists. Therefore something like a dropped tool or an unanchored part cant activate the script.
script.Parent.Touched:Connect(function(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
Characters = Characters+1
print("A player has touched the van")
Here we make the current amount of characters in the van raise by 1 everytime a player touches the van.
script.Parent.Touched:Connect(function(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
Characters = Characters+1
print("A player has touched the van")
if Characters == NeededCharacters then
print("Van is full!")
Here we can check if the van has been filled up yet to the maximum amount of players which is 10
local PlayerTouched = false
if PlayerTouched == true then end
PlayerTouched = true
Here we add a debounce to stop a single player from activating this script multiple times.
function PlayerEntered(c)
script.Parent.Touched:Connect(PlayerEntered)
I like naming my functions allowing them to be much more easy to get.
Now we have.
local NeededCharacters = 10
local Characters = 0
local PlayerTouched = false
function PlayerEntered(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
if PlayerTouched == true then return end
PlayerTouched = true
Characters = Characters+1
print("A player has touched the van")
if Characters == NeededCharacters then
print("Van is full!")
end
end
end)
script.Parent.Touched:Connect(PlayerEntered)
Now we make a function to remove players that left the van
local PlayerLeft = false
function PlayerLeft(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
if PlayerLeft == true then return end
PlayerLeft = true
Characters = Characters-1
print("A player has left the van")
end
end
end)
script.Parent.TouchEnded:Connect(PlayerLeft)
So now our final script should be.
local NeededCharacters = 10
local Characters = 0
local PlayerTouched = false
local PlayerLeft = false
function PlayerEntered(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
if PlayerTouched == true then return end
PlayerTouched = true
Characters = Characters+1
print("A player has touched the van")
if Characters == NeededCharacters then
print("Van is full!")
end
end
end)
function PlayerLeft(c)
if c.Parent:FindFirstChild("Masked") ~= nil then
if PlayerLeft == true then return end
PlayerLeft = true
Characters = Characters-1
print("A player has left the van")
end
end
end)
script.Parent.Touched:Connect(PlayerEntered)
script.Parent.TouchEnded:Connect(PlayerLeft)
If it doesn't work please tell me what I did wrong! :D
1 comment
i dont want any values included plz