#trying to make a gun with a roblox model with my script but i literally cannot use the gun.
25 messages · Page 1 of 1 (latest)
Check if you have a part named "Handle" in your tool
Is it working?
Whats so hard to understand?
-- Variables
local player = game.Players.LocalPlayer
local gun = script.Parent -- Assuming the script is a child of the gun model
local shooting = false
local shootCooldown = 0.1 -- Adjust as needed
local lastShotTime = 0
local function shoot()
if shooting and (tick() - lastShotTime) >= shootCooldown then
lastShotTime = tick()
-- Create a bullet or projectile here
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(0.2, 0.2, 1)
bullet.BrickColor = BrickColor.new("Bright red")
bullet.Position = gun.Muzzle.Position -- Assuming Muzzle is a child part of the gun
bullet.Velocity = gun.Muzzle.CFrame.LookVector * 100 -- Adjust the velocity as needed
bullet.Parent = game.Workspace
-- Handle hit detection and damage here if required
-- Play shooting sound and animation
local sound = gun:FindFirstChild("GunSound")
local animation = gun:FindFirstChild("GunAnimation")
if sound then
sound:Play()
end
if animation then
animation:Play()
end
end
end
-- Bind shooting to a mouse click
local function onMouseClick()
if player:GetMouse().Button1Down then
shooting = true
shoot()
else
shooting = false
end
end
player:GetMouse().Button1Down:Connect(onMouseClick)
Chat GPT?
** You are now Level 2! **
No wonder is not working...
Thats a tool, right?
What?
Anyway, you should do something like:
local tool = YOUR_TOOL
function onActivated()
print("Tool has been activated")
end
tool.Activated:Connect(onActivated)
skills