I have 4 models in replicated storage named LootTools1 to LootTools4 and they all have 2 apple parts with ClickDetectors in them. What I want is for my local script to find the model then destroy the part if i click it.
Current Local Script
-- Replicated Storage where the models are stored
local replicatedStorage = game:GetService("ReplicatedStorage")
-- Specify the models to target
local modelsToTarget = {
replicatedStorage.LootTools1,
replicatedStorage.LootTools2,
replicatedStorage.LootTools3,
replicatedStorage.LootTools4
}
local function onToolClick(player, part)
if part.Name == "ApplePickUp1" or part.Name == "ApplePickUp2" then
part:Destroy()
print("Destroyed: " .. part.Name) -- Print the name of the destroyed part
end
end
local function setupClickDetector(model)
local clickDetector = model:FindFirstChild("ClickDetector")
if clickDetector then
clickDetector.MouseClick:Connect(function()
for _, part in pairs(model:GetChildren()) do
onToolClick(game.Players.LocalPlayer, part)
end
end)
end
end
for _, model in pairs(modelsToTarget) do
setupClickDetector(model)
end
This is still unsolved giving 200 to the person who can solve it. what i want is 4 random models and only one that spawns into workspace which i have already then the parts in the model when you click them they destroy for only the person who clicked it so through a local script.
no so what i want is when you click the part that spawns in one of the 4 random models the local script in startercharacterscripts knows which one you click and destroys it locally so only for the one player.
kind of so to give you context there are 4 models in each of the models there is 2 apples 2 cookies and 1 bloxy cola you can click each one for 1 tool but I just want it to destroy for the player locally.
i want it to be a click detector through client side but the problem is one of the 4 models spawns and I dont know how to make the local script know which model spawned so that it can find the clickable part to destroy after its clicked.
Then put a local script inside the StarterCharacterScripts and put the following,
local Models = game.Workspace.<Your Models Folder>
for _, Model in pairs(Models:GetChildren()) do
if Model["ClickDetector"] then
Model["ClickDetector"].MouseClick:Connect(function()
Model:Destroy()
end)
end
end
the 4 models are in replicated storage though and only 1 randomly spawns per game so the local script needs to find the model with all the click parts in them.
You need to clarify what you want more specifically, use grammar because I do not understand half of your sentences, also include your model structure, and model example using an image or a list of what is in your model, then explain how you spawn them, or if you even do and if it is local or server sided.