RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"working pistol and equippable part comments explaining where to put everything"
-- script for the pistol part (Tool) local tool = script.Parent local equipped = false local canShoot = true local debounce = false local function shoot() if equipped and canShoot then canShoot = false local ray = Ray.new(tool.Handle.Position, tool.Handle.CFrame.lookVector * 1000) local part, position = workspace:FindPartOnRay(ray, tool.Parent) local distance = (tool.Handle.Position - position).magnitude local bullet = Instance.new("Part") bullet.Size = Vector3.new(0.2, 0.2, distance) bullet.BrickColor = BrickColor.new("Bright red") bullet.Anchored = true bullet.CFrame = CFrame.new(tool.Handle.Position, position) * CFrame.new(0, 0, -distance / 2) bullet.Parent = workspace wait(0.1) bullet:Destroy() wait(0.5) canShoot = true end end tool.Activated:Connect(shoot) local function onEquipped() equipped = true end local function onUnequipped() equipped = false end tool.Equipped:Connect(onEquipped) tool.Unequipped:Connect(onUnequipped) -- Put the script above in a Tool object in StarterPack. Create a part named "Handle" inside the Tool object and position it as the pistol model. -- script for the equippable part (StarterPack) local part = script.Parent local debounce = false local function onTouch(hit) local character = hit.Parent local humanoid = character:FindFirstChild("Humanoid") if humanoid and not debounce then debounce = true local toolClone = game.ServerStorage.Pistol:Clone() toolClone.Parent = character.Backpack part:Destroy() end end part.Touched:Connect(onTouch) -- Put the script above in a part that you want to be equippable. Place the part anywhere in the Workspace. Also, make sure to create a copy of the Tool object from StarterPack and place it in ServerStorage, naming it "Pistol". This will be cloned when a player touches the equippable part.