so basically, im trying to make local parts by cloning parts from a folder using a local script
then, when you touch the items, it is destroyed, but only in your side
however, it doesnt seem to spawn at workspace, even when i added PlayerAdded and CharacterAdded
here is the script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local itemsFolder = replicatedStorage:WaitForChild("Items")
local items = itemsFolder:GetChildren()
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, part in ipairs(items) do
local clientItems = part:Clone()
clientItems.Parent = workspace.Items --this is the folder where the cloned items are supposed to go
print("Local items have been added")
if clientItems:IsA("BasePart") then
local isTouched = clientItems:WaitForChild("IsTouched")
isTouched = false
clientItems.Touched:Connect(function(hit)
if not isTouched then
isTouched = true
clientItems:Destroy()
end
end)
end
end
end)
end)
i’m not 100% sure on how localscripts work but theres 2 issues with this. 1) i’m not sure if localscripts run on the client if they’re not in the player (i have to look this up i do not definitively know) and 2) you’re running PlayerAdded in a local script, for a player to run that, they have to be in the game meaning that event is Binded after they’ve loaded in. PlayerAdded won’t be fired unless another player joins in
Can’t test right now, but my best guess is that you shouldn’t use game.Players.PlayerAdded as it will not fire on your side but it will fire when someone else joins. Remove that, and instead of player.CharacterAdded, use game.Players.LocalPlayer.CharacterAdded.