for _, Pad in pairs(Pads) do
Pad.Touched:Connect(function(hit)
print("touched")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
AddPlayer(player, Pad)
end)
end
You need to check if the part you touched is part of a character model:
for _, Pad in pairs(Pads) do
Pad.Touched:Connect(function(hit)
print("touched")
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
AddPlayer(player, Pad)
end
end)
end
-- Pad Service
-- FerbZides
-- August 23, 2020
--[[
Server:
Client:
--]]
local PadService = {Client = {}}
local PathfindingService = game:GetService("PathfindingService")
local CollectionService = game:GetService("CollectionService")
local PadsPart = CollectionService:GetTagged("Pads")
-- Events
local PLAYER_LEFT = "PlayerLeft"
function PadService:Start()
-- move them to the part and their walkspeed
local function MovePlayers(Player, Part, Speed)
-- Define humanoid then move them
local character = Player.Character
local Humanoid = character.Humanoid
-- Change speed
Humanoid.WalkSpeed = Speed
local path = PathfindingService:CreatePath()
path:ComputeAsync(character.HumanoidRootPart.Position, Part.Position)
for _, WayPoints in pairs(path:GetWayPoints()) do
Humanoid:MoveTo(WayPoints.Position)
Humanoid.MoveToFinished:wait()
end
end
-- just to check if they are a real character
local function PlayerIsInGame(Player)
if Player then
if Player.Character then
return true
end
end
end
-- Pad functions
-- Add player
local function AddPlayer(Player, Part)
if PlayerIsInGame(Player) then
-- Define part values
local Taken = Part.Taken
local PadOwner = Part.Owner
-- Define its stats
local PadData = Player:WaitForChild("PadData")
local CourtName = PadData:WaitForChild("CourtName")
local PadName = PadData:WaitForChild("PadName")
local OnSpot = PadData:WaitForChild("OnSpot")
local TeamName = PadData:WaitForChild("TeamName")
-- Define the court
local CourtFolder = Part.Parent.Parent.Parent
local Config = CourtFolder.Configuration
local GamePlayers = Config.GamePlayers
local Team1Folder = GamePlayers.Team1
local Team2Folder = GamePlayers.Team2
-- Functions
local function CheckPlayers()
local CheckNumber = 0
for _, Player in pairs(game.Players:GetPlayers()) do
-- check then add 1
if Team1Folder:FindFirstChild(Player.Name) then
CheckNumber = CheckNumber + 1
elseif Team2Folder:FindFirstChild(Player.Name) then
CheckNumber = CheckNumber + 1
end
end
-- returning it to whoever called it
return CheckNumber
end
-- Checks then add
if OnSpot.Value == false and CourtName.Value ~= CourtFolder.Name and Taken.Value == false and PadOwner.Value == "" then
-- Move them
Part.Decal.Color3 = Color3.fromRGB(255, 115, 0)
MovePlayers(Player, Part, 0)
-- Add value
local Value = Instance.new("StringValue")
Value.Name = Player.Name
Value.Value = tonumber(Part.Name)
-- set it after the check
if Part.Parent.Name == "Team1" then
Value.Parent = Team1Folder
elseif Part.Parent.Name == "Team2" then
Value.Parent = Team2Folder
end
-- Set stats
CourtName.Value = CourtFolder.Name
PadName.Value = tonumber(Part.Name)
OnSpot.Value = true
TeamName.Value = Part.Parent.Name
end
end
end
-- Remove player
local function RemovePlayer(Player, Part)
if PlayerIsInGame(Player) then
-- Define part values
local Taken = Part.Taken
local PadOwner = Part.Owner
-- Define its stats
local PadData = Player:WaitForChild("PadData")
local CourtName = PadData:WaitForChild("CourtName")
local PadName = PadData:WaitForChild("PadName")
local OnSpot = PadData:WaitForChild("OnSpot")
local TeamName = PadData:WaitForChild("TeamName")
-- Define the court
local CourtFolder = Part.Parent.Parent.Parent
local TPBack = CourtFolder.TPBack
local Config = CourtFolder.Configuration
local MainValues = Config.MainValues
local GameRunning = MainValues.GameRunning
local GamePlayers = Config.GamePlayers
local Team1Folder = GamePlayers.Team1
local Team2Folder = GamePlayers.Team2
-- Functions
local function CheckPlayers()
local CheckNumber = 0
for _, Player in pairs(game.Players:GetPlayers()) do
-- check then add 1
if Team1Folder:FindFirstChild(Player.Name) then
CheckNumber = CheckNumber + 1
elseif Team2Folder:FindFirstChild(Player.Name) then
CheckNumber = CheckNumber + 1
end
end
-- returning it to whoever called it
return CheckNumber
end
-- check if they are on the team then destroy it
local function RemoveValue()
if Team1Folder:FindFirstChild(Player.Name) then
local Obj = Team1Folder:FindFirstChild(Player.Name)
Obj:Destroy()
elseif Team2Folder:FindFirstChild(Player.Name) then
local Obj = Team2Folder:FindFirstChild(Player.Name)
Obj:Destroy()
end
end
-- checks then remove
if OnSpot.Value == true and GameRunning.Value == false and CourtName.Value == CourtFolder.Name and OnSpot.Value == true and PadName.Value == tonumber(Part.Name) then
Part.Decal.Color3 = Color3.fromRGB(255,255,255)
MovePlayers(Player, TPBack, 16)
RemoveValue()
-- Set stats
CourtName.Value = "COURT_0"
PadName.Value = 0
OnSpot.Value = false
TeamName.Value = "No Team"
end
end
end
for _, PadPart in pairs(PadsPart) do
print("it ran")
PadPart.Touched:Connect(function(hit)
print("touched")
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
AddPlayer(player, PadPart)
end
end)
end
end
function PadService:Init()
self:RegisterEvent(PLAYER_LEFT)
end
return PadService