Currently using this script to detect if a player is touching a part:
local Part = workspace.FreeMove
Part.Touched:Connect(function() end) -- Just for a TouchInterest to occur on a CanCollide false part
function CheckIfPlayerIsInArea(Part,Character)
local touching = Part:GetTouchingParts()
for i=1,#touching do
if touching[i] == Character.HumanoidRootPart then
return true
end
end
return false
end
How do I implement this with multiple parts called workspace.FreeMove? (I want this function to apply to all parts with that name)
I would say you would want to update the variable of the part in a for loop and add 1 major connection (which would also update per part) for the Touched event.
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "FreeMove" then
local Part = workspace.FreeMove
Part.Touched:Connect(function() end) -- Just for a TouchInterest to occur on a CanCollide false part
end
end
function CheckIfPlayerIsInArea(Part,Character)
local touching = Part:GetTouchingParts()
for i=1,#touching do
if touching[i] == Character.HumanoidRootPart then
return true
end
end
return false
end
So if you are making ckeckpoints why aren’t you doing something like this:
local chackpoints = workspace.Checkpoints
for _, checkpoint in ipairs(checkpoints:GetChildren()) do
if checkpoint:IsA("BasePart") then
checkpoint.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local player = game.Players:GetPlaerFromCharacter(hit.Parent)
player.TeamColor = BrickColor.new()
end
end)
end
end
Anyway, no I’m not looking to make checkpoints. My game does not allow you to go backwards (left), nor stand still. The semi-transparent areas are supposed to be safe, where you can move backwards and stand still.
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "FreeMove" then
v.Touched:Connect(function() end) --TouchInterest will appear in all FreeMove parts
end
end
function CheckIfPlayerIsInArea(Part,Character)
local touching = Part:GetTouchingParts()
for i=1,#touching do
if touching[i] == Character.HumanoidRootPart then
return true
end
end
return false
end