I made a hold script but whenever I hold an object if I have another duplicated object that is the same it will hold that one too? Why is this?
Script:
db = false
game.ReplicatedStorage.Start.OnServerEvent:Connect(function(player, camPos)
local throwOffset = 10 --studs in front of head for part to spawn
local head = player.Character.Head
local newPos = head.Position + camPos*throwOffset
script.Parent.Parent.PrimaryPart.CFrame = CFrame.new(newPos,newPos+camPos)
end)
local touched = script.Parent.Parent.PrimaryPart.Touched:Connect(function() end) touched:Disconnect()
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
if db == false then
db = true
for index, instance in pairs(script.Parent.Parent:GetDescendants()) do
if instance:IsA("BasePart") then
instance.CanCollide = false
end
end
game.ReplicatedStorage.Grab:FireClient(player)
script.Parent.Parent.PrimaryPart.Anchored = true
else
for index, instance in pairs(script.Parent.Parent:GetDescendants()) do
if instance:IsA("BasePart") then
instance.CanCollide = true
end
end
db = false
game.ReplicatedStorage.Drop:FireClient(player)
wait(0.5)
script.Parent.Anchored = false
local OP = OverlapParams.new()
OP.FilterDescendantsInstances = {script.Parent.Parent, player.Character} --Blacklist
OP.FilterType = Enum.RaycastFilterType.Blacklist
local Hit = game.Workspace:GetPartsInPart(script.Parent, OP)
if #Hit <= 0 then return end
script.Parent.Anchored = true
end
end)