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

Gun server script doesnt work AND doesnt give error output?

Asked by
RAFA1608 543 Moderation Voter
4 years ago
Edited 4 years ago

Heres the serverscript for a gun i've been working on. But, it doesnt appear to do anything nor returns error message.

local lighting = game.Lighting
local player = nil
local ignorelist = Instance.new("Model",lighting)
local tool = script.Parent
local sanim = script:WaitForChild("Shootanim") -- theres a holding animation in a local script (which only does the holding animation)
local firepart = script.Parent:WaitForChild("firepart")
local char = nil
local sanima = nil
local sooldown = false
local gui = script:WaitForChild("GlockGUI")
local gui2 = nil
local maxstock = 60 --max stock of ammo you can carry
local ammo = 8 --ammo shot before needing to reload
local ammoreloadwait = 1 --1 seconds to reload
local reloading = false
local ammogui = gui.AmmoInfo.CurrentAmmo
local ammostockgui = gui.AmmoInfo.AmmoStock
local human = nil
tool.Equipped:Connect(function(mouse) --i didnt make the reload part yet
    player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
    char = player.Character
    if char ~= nil then
        local hum = char:FindFirstChildWhichIsA("Humanoid")
        if hum then
            human = hum
        end
    end
    gui2 = gui:Clone()
    gui2.Parent = player.PlayerGui
    --tool.Activated:Connect(function()
    mouse.Button1Down:Connect(function()
        if sooldown == true then return end
        if ammo == 0 then return end
        sooldown = true
        local hit = mouse.Hit
        local ray = Ray.new(firepart.CFrame.Position,(hit.Position - firepart.CFrame.Position).unit*300)
        local hitpart,pos = workspace:FindPartOnRay(ray,script.Parent.Parent,false,false)
        local distance = (firepart.CFrame.Position - pos).magnitude
        local trail = Instance.new("Part")
        trail.Material = Enum.Material.Neon
        trail.CanCollide = false
        trail.Anchored = true
        trail.BrickColor = BrickColor.new("Bright yellow")
        trail.Transparency = 0.25
        trail.Size = Vector3.new(0.25,0.25,distance)
        trail.CFrame = CFrame.new(firepart.CFrame.Position,pos) * CFrame.new(0,0,-distance/2)
        --game.Debris:AddItem(trail,0.5)
        sanima = human:LoadAnimation(sanim) --shooting animation
        sanima:Play()
        trail.Parent = workspace
        ammo = ammo - 1
        wait(0.267)
        sanima:Stop()
        sanima:Destroy()
        sooldown = false
    end)
end)
tool.Unequipped:Connect(function()
    if gui2 ~= nil then
        gui2:Destroy()
    end
end)

I suspect the mouse is inactive. Thank you.

1 answer

Log in to vote
1
Answered by 4 years ago

Server cannot track the player's mouse. You must use a local script to communicate that.

The local script should handle animations and player inputs. When they fire the mouse you should include information like their mouse position. Depending on your security measures, you can keep ammo, firerate, and raycasting on the server.

You can also render the raycast on the client and replicate it to everyones' screen locally. That way when the player shoots, it looks instantaneous on their own screen while delayed on others.

0
Didnt know that. Thank you. RAFA1608 543 — 4y
Ad

Answer this question