Thanks. I’ve tweaked the code a bit, unfortunately using chatgpt because it didnt really work how i wanted it to. Good news is that the script works well. Bad news is that it’s a bit laggy and the weapons can still be collected even when it is not cloned from ReplicatedStorage.
Do I change the tools to models instead and grant the tools thru that code then? because the tools are still tools in workspace.
(Tweaked server code) -- local script is still the same/very similar
Stoppickupevent.OnServerEvent:Connect(function(player) -- taking the event from your Local
--print("Fired stopPickup!")
if not blockedPlayers[player.UserId] then
blockedPlayers[player.UserId] = true
print("Blocked player:", player.Name)
else
print("Player already blocked:", player.Name)
end
end)
local function handlePickup(tool, player)
if not player or blockedPlayers[player.UserId] then return end
local weaponTemplate = WeaponsStorage:FindFirstChild(tool.Name)
if not weaponTemplate then return end
local clonedTool = weaponTemplate:Clone()
clonedTool.Parent = player.Backpack
print("Tool granted to Player!")
if clonedTool:FindFirstChild("Model") then
clonedTool.Model.Anchored = false
end
if clonedTool:FindFirstChild("Handle") then
clonedTool.Handle.Anchored = false
end
tool:Destroy()
task.wait(delayTime)
PickupEvent:FireClient(player)
SpawnWeaponsEvent:Fire(clonedTool.Name)
end
-- Connect touch for any valid tool
local function connectTool(tool)
if not tool:IsA("Tool") then return end
local touchPart = tool:FindFirstChild("Model") or tool:FindFirstChild("Handle")
if not touchPart then return end
touchPart.Touched:Connect(function(hit)
local character = hit:FindFirstAncestorOfClass("Model")
local player = Players:GetPlayerFromCharacter(character)
handlePickup(tool, player)
end)
end
-- Initial tools in workspace folder
for i, tool in pairs(WeaponSpawner:GetChildren()) do
if tool:IsA("Tool") then
connectTool(tool)
end
end
--New spawned tools
WeaponSpawner.ChildAdded:Connect(connectTool)