Hello, I’m trying to make a gun script, that can players. I’ve tested it on Xbox, IPad, Phone, and Computers. Only Computers work, and the others don’t. Scripts:
Client Script (LocalScript):
local tool = script.Parent
local maxammo = 13
local CoolDown = 0.23
local ammo = maxammo
local reloading = false
local plr = game.Players.LocalPlayer
local plrgui = plr:WaitForChild("PlayerGui")
local text = plrgui:WaitForChild("Ammo"):FindFirstChild("AmmoCount")
local Mouse = plr:GetMouse()
script.Parent.Equipped:Connect(function()
plr.CameraMode = Enum.CameraMode.LockFirstPerson
plrgui.Ammo.Enabled = true
text.DisableScript.Disabled = true
plrgui.Shop.Enabled = false
local function reload()
reloading = true
wait(1)
script.Parent.reload:Play() -- change reloadingsound to what ever your reload sound is named
ammo = maxammo
reloading = false
end
script.Parent.Activated:Connect(function()
local TargetPos = plr.Character:FindFirstChildOfClass("Humanoid").TargetPoint
if ammo > 0 and not reloading then
ammo = ammo - 1
script.Parent.gunshot:Play() -- change gunshot to what ever your gun shot sound is named
wait(CoolDown)
local targetHumanoid = Mouse.Target.Parent:FindFirstChild("Humanoid")
if targetHumanoid then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, math.random(15,30)) -- change the 25 to what ever amount of damage you want to deal
local player = game.Players.LocalPlayer
end
elseif reloading == false then
reload()
script.Parent.gunshot:Stop()-- change gunshot to what ever your gun shot sound is named
end
while wait() do
text.Text = (ammo).." / "..tostring(maxammo)
end
end)
local input = game:GetService("UserInputService")
input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and reloading == false and ammo ~= maxammo then
reload()
end
end)
local input = game:GetService("UserInputService")
input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.ButtonY and reloading == false and ammo ~= maxammo then
reload()
end
end)
end)
script.Parent.Unequipped:Connect(function()
plrgui.Ammo.Enabled = false
text.DisableScript.Disabled = false
plrgui.Shop.Enabled = true
plr.CameraMode = Enum.CameraMode.Classic
end)
Server Script (Normal Script):
local db = false
script.Parent.DealDamage.OnServerEvent:Connect(function(player, Target, Damage)
Target.Humanoid:TakeDamage(Damage)
if Target.Humanoid.Health <= 0 then
if db == false then
db= true
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 15
player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
task.wait(3)
db = false
end
end
end)
Animation Script (LocalScript):
local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=9810835061"
local track
tool.Equipped:Connect(function()
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = true
track:Play()
end)
tool.Unequipped:Connect(function()
if track then
track:Stop()
end
end)
Please help soon,
– papahetfan