Greetings, I tried to make a gun, a Glock17, and made those scripts which makes you able to shoot, reload, double damage touching the enemy's head, with guis, animations, compatible in mobile, and compatible with Filtering Enabled on, but it doesn't work for some reason. Could I get some help, please?
1st Script, inside the tool:
local Tool = script.Parent --Getting the Tool
local Player = game:GetService("Players").LocalPlayer -- Getting the Player
local Mouse1 = Player:GetMouse() -- Getting Player's Mouse
local GunFire = Tool:WaitForChild("GunFire") -- Getting the Shoot sound
local Reload = Tool:WaitForChild("Reload") -- Getting the Reload sound
local Torso = "" -- Getting the Player's Torso
local Reloading = false -- Prevents spamming the reload event
local ContextActionService = game:GetService("ContextActionService") -- Allows us to cater for Mobile Players
local BodyType = nil -- Getting the player's bodytype (R6 or R15), nil for now
local Difference = 0 -- Geting distance between the bullet and the gun
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting ReplicatedStorage
local GunGui = Tool:WaitForChild("GunGui") -- Getting the Gui
local Bullets = Tool:WaitForChild("Bullets") -- Getting the Bullets
local ReloadTime = 3 -- Setting the Reload Time
-- [[REMOTE EVENTS]]
local EquipAnimation = ReplicatedStorage:WaitForChild("EquipAnimation") -- Getting Remote event
local Headshot = ReplicatedStorage:WaitForChild("Headshot") -- Getting Remote event
local Reload = ReplicatedStorage:WaitForChild("Reload") -- Getting Remote event
local ShootEvent = ReplicatedStorage:WaitForChild("ShootEvent") -- Getting Remote event
local UnequipAnimation = ReplicatedStorage:WaitForChild("UnequipAnimation") -- Getting Remote event
-- [[REMOTE FUNCTIONS]]
local CheckBodyType = ReplicatedStorage:WaitForChild("CheckBodyType") -- Getting Remote Function
local FetchBulletsLeft = ReplicatedStorage:WaitForChild("FetchBulletsLeft") -- Getting Remote Function
-- [[FIND BODY TYPE]]
function FindBodyType() -- Getting the player's bodytype (R6 or R15)
BodyType = CheckBodyType:InvokeServer(Tool) -- Invoking Remote Function checking if player's bodytype is R6 or R15
print(BodyType) -- Print the bodytype of the player
end
-- [[RELOADING FUNCTION]]
function ReloadFunction()
Reloading = true
Reload:FireServer(Tool.Reload)
Mouse1.Icon = "http://www.roblox.com/asset?id=936489170"
Player.PlayerGui:WaitForChild("GunGui").Frame.Bullets.Text = "Reloading..."
wait(ReloadTime)
Bullets.Value = 30
Player.PlayerGui:WaitForChild("GunGui").Frame.Bullets.Text = (Bullets.."/30")
Mouse1.Icon = "http://www.roblox.com/asset?id=936803887"
EquipAnimation:FireServer(Tool.Shoot)
Reloading = false
end
-- [[TOOL EQUIPING]]
Tool.Equipped:Connect(function(mouse)
GunGui:Clone().Parent = Player.PlayerGui -- Adding the Gui to the Player's Gui
FindBodyType() -- Calling FindBodyType Function
EquipAnimation:FireServer(Tool.Shoot) -- Calling the equipanimation event so the server can play the animation
Mouse1.Icon = "http://www.roblox.com/asset?id=936803887" --Changing mouse Icon
mouse.Button1Down:Connect(function()
if Bullets.Value <= 0 or Reloading == true then
-- Don't do anything
else
local Head = game.Workspace[Player.Name].Head.CFrame.LookVector
local Mouse2 = CFrame.new(game.Workspace[Player.Name].Head.Position, Mouse1.Hit.p).LookVector
Difference = (Head-Mouse2)
local ray = Ray.new(Tool.Handle.CFrame.Position,(Player:GetMouse().Hit.Position - Tool.Handle.CFrame.Position.Unit * 300))
local Part,Position = game.Workspace:FindPartOnRay(ray,Player.Character,false,true)
GunFire:Play()
if Difference.Magnitude < 1.33 then
ShootEvent:FireServer(Tool,Position,Part)
Bullets.Value = Bullets.Value - 1
end
end
end)
local ReloadMobileButton = ContextActionService:BindAction("ReloadButton",ReloadFunction(),true,"r")
ContextActionService:SetPosition("ReloadButton",UDim2.new(0.72,-25,0.2,-25))
ContextActionService:SetImage("ReloadButton","http://www.roblox.com/asset?id=10952420")
end)
-- [[UNEQUIPPING TOOL]]
Tool.Unequipped:Connect(function()
Mouse1.Icon = ""
UnequipAnimation:FireServer(Tool.shoot)
Player.PlayerGui.GunGUI:Destroy()
ContextActionService:UnbindAction("ReloadBtn")
end)
Headshot.OnClientEvent:Connect(function()
Player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(0.5,-100,0.5,-25), "Out","Quint",0.3)
wait(1.5)
Player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(-1,0,0.5,-25), "In","Quint",0.4)
wait(0.5)
Player.PlayerGui.GunGUI.Headshot.Position = UDim2.new(1.5,0,0.5,-25)
end)
2nd Script, inside ServerScriptService
local serverStorage = game:GetService("ServerStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")
local KOValue = "Kills"
local WOValue = "Wipeouts"
local damage = 30
replicatedStorage.ShootEvent.OnServerEvent:Connect(function(player,tool,position,part)
if game.Workspace[player.Name].Humanoid.Health <= 0 then
-- The player is dead, do not do anything
else
local distance = (tool.Handle.CFrame.p - position).magnitude
if game.Workspace:FindFirstChild(player.Name.."'s Trajectory") then
game.Workspace:FindFirstChild(player.Name.."'s Trajectory"):Destroy()
end
local trajectory = Instance.new("Part",game.Workspace)
local smoke = serverStorage.SmokeParticle:Clone()
smoke.Parent = tool.Handle
trajectory.BrickColor = BrickColor.new("Institutional white")
trajectory.Material = "SmoothPlastic"
trajectory.Name = player.Name.."'s Trajectory"
trajectory.Transparency = 0.5
trajectory.Anchored = true
trajectory.Locked = true
trajectory.CanCollide = false
trajectory.Size = Vector3.new(0.3,0.3,distance)
for i = 0,distance,6 do
trajectory.CFrame = CFrame.new(tool.Handle.CFrame.p,position) * CFrame.new(0,0,-distance / 2)
wait(0.0001)
end
smoke:Destroy()
if part then
if part.Name == "Head" or part:IsA("Hat") and part.Parent:FindFirstChild("Humanoid").Health > 0 then
-- Boom headshot
replicatedStorage.Headshot:FireClient(player)
damage = 50
end
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
else
humanoid:TakeDamage(damage)
if humanoid.Health <= 0 then
player.leaderstats[KOValue].Value = player.leaderstats[KOValue].Value + 1
game.Players[humanoid.Parent.Name].leaderstats[WOValue].Value = game.Players[humanoid.Parent.Name].leaderstats[WOValue].Value + 1
end
end
wait(0.25)
if trajectory then
trajectory:Destroy()
end
end
end
end)
replicatedStorage.EquipAnimation.OnServerEvent:Connect(function(player,animation)
local newAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
newAnim:Play()
replicatedStorage.UnequipAnimation.OnServerEvent:Connect(function(player,animation)
newAnim:Stop()
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == player.Name.."'s Trajectory" then
v:Destroy()
end
end
end)
replicatedStorage.Reload.OnServerEvent:Connect(function(player,animation)
newAnim:Stop()
local reloadAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
reloadAnim:Play()
end)
end)
function checkBodyType(player,tool)
if game.Workspace[player.Name]:FindFirstChild("LowerTorso") then -- R15
tool.shoot.AnimationId = "rbxassetid://936531673"
tool.reload.AnimationId = "rbxassetid://937806099"
return "R15"
end
if game.Workspace[player.Name]:FindFirstChild("Torso") then -- R6
tool.shoot.AnimationId = "rbxassetid://1000874313"
tool.reload.AnimationId = "rbxassetid://937933712"
return "R6"
end
end
replicatedStorage.CheckBodyType.OnServerInvoke = checkBodyType

9 comments
You scripted this? Or AlvinBlox?
AlvinBlox
But the thing is that when I made the script following the tutorial, I realised that some parts were probably deprecated, or replaced by some other features, and I don't know which are those features.
Any errors in the output?
shoot is not a valid member of Tool, maybe a mistake in the script
is the error in the LocalScript? Server script what line is it
can u space the parts out bc all of it looks like one
It also says 21:37:32.932 - Stack Begin 21:37:32.933 - Script 'Players.Time_URSS.Backpack.Glock17.GunScript', Line 26 - global FindBodyType 21:37:32.934 - Script 'Players.Time_URSS.Backpack.Glock17.GunScript', Line 45 21:37:32.935 - Stack End
Website guideline: Attempts should be your own work. Don't take a free model and expect us to fix it.^ Though this isn't a free model, it is ntnofyour own work and you straight up copy pasted this.