Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gun script works in studio but doesnt run in a server?(Uses raycasting)

Asked by
Galicate 106
6 years ago

My script works in studio but not in a server. Ive put it in a localscript and normal script and it still doesnt work

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local Ammo = script.Parent:WaitForChild("Ammo")
HoldAnimation = script.Parent.HoldAnim
tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        if Ammo.Value >= 1 then
        print("Mouse pressed!")
        Ammo.Value = Ammo.Value - 1
        print(Ammo.Value)
        script.Parent.Handle.Fire:Play()
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Bright red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.5
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Handle.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)


        game:GetService("Debris"):AddItem(beam, 0.1)

        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

            if humanoid then
                humanoid:TakeDamage(10)

            end
        end
        end
        end)
end)

local Player = game.Players.LocalPlayer
local action_reload = false
Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "r") and Ammo.Value < 7 and action_reload == false then
        action_reload = true
        script.Parent.Handle.Reload:Play()
        wait(2)
        Ammo.Value = 7
        print(Ammo.Value)
        action_reload = false
    end
end)
0
Could you tell me the output error? TinfoilbotGamer 35 — 6y
0
There is none, it simply will not fire or play sound. Galicate 106 — 6y

Answer this question