Hey!
So I have three spawn locations, a big part (transparent, not collidable) that acts as area to name the location.
The big part was supposed to fire Touched event when the player touches the big part (so as to give information about the fact the the player is in another area.)
But there is a problem with this.
When the gameplay pauses, sometime it causes it to trigger twice. This happens when the player joins and is teleported to one of these spawn locations, anyone know why?
VIDEO BELOW
PICTURE SHOWING THE BIG PART
A script for teleporting the player to these spawn location when joining the game:
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local locations = CollectionService:GetTagged("SpawnLocation")
local function onCharacterAdded(character: Model)
local humanoid : Humanoid = character:FindFirstChild("Humanoid")
local location = locations[math.random(#locations)]
local locationCFrame = CFrame.new(location.CFrame.Position)
locationCFrame *= CFrame.Angles(0, math.rad(150), 0)
print(locationCFrame)
character:PivotTo(locationCFrame)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Another script for handling Touched Event and for the big part.
-- Service
local ServerStorage = game:GetService("ServerStorage")
-- Libraries
-- Events
local OnWorldEnter = ServerStorage["Bindable Events"]["Universe Events"].OnWorldEnter
local OnWorldLeave = ServerStorage["Bindable Events"]["Universe Events"].OnWorldLeave
local OnAreaEnter = ServerStorage["Bindable Events"]["Universe Events"].OnAreaEnter
local OnAreaLeave = ServerStorage["Bindable Events"]["Universe Events"].OnAreaLeave
-- Module Services
-- Initalizing Variables
local worldsList = workspace.Worlds:GetChildren()
local touchAreasList = {}
-- Scripts
for _, world in pairs(worldsList) do
local areasFolder = world.Areas:GetChildren()
for _, area in pairs(areasFolder) do
local touchPart = area.Touch.touchArea
table.insert(touchAreasList, touchPart)
end
end
for _, touchArea : Part in pairs(touchAreasList) do
print("connecting")
touchArea.Touched:Connect(function(partTouching)
if partTouching.Name == "HumanoidRootPart" then
print("true!!!")
end
end)
end