- What do you want to achieve? Keep it simple and clear!
I want to add models/parts into the workspace with tags so that the server can use and change them.
- What is the issue?
The problem is when I clone an instance into the workspace, the server won’t recognize the part’s tag.
Server
local CollectionService = game:GetService("CollectionService")
local ServerStorage = game:GetService("ServerStorage")
local Spawns = ServerStorage.Spawns
local function findPart(tag)
local relative = tag:GetAttribute("RelativePlate")
for _,part in ipairs(tag.Parent:GetChildren()) do
if part.Name == relative then
return part
end
end
end
local function findTag(tag)
for _,touchPart in ipairs(tag.Parent:GetChildren()) do
if touchPart.Name == "TouchPart" then
CollectionService:AddTag(touchPart,"Touch")
end
end
end
local function createSpawn(tag)
local relativePart = findPart(tag)
local chosenSpawn = Spawns.Spawn:Clone()
chosenSpawn.Parent = workspace
chosenSpawn:PivotTo(tag.CFrame)
chosenSpawn:MoveTo(relativePart.Position)
findTag(tag)
end
local function cleanTags(tag)
for _,touchPart in ipairs(tag.Parent:GetChildren()) do
if touchPart.Name == "TouchPart" then
touchPart:SetAttribute("Touched",true)
end
end
end
for _,tag in ipairs(CollectionService:GetTagged("Touch")) do
tag.Touched:Connect(function()
local touched = tag:GetAttribute("Touched")
if not touched then
cleanTags(tag)
createSpawn(tag)
end
end)
end
-
What solutions have you tried so far?
I’ve tried manually adding the tag in a pairs loop but it hasn’t worked.