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

I'm having issues with a basic reload system value change, please help?

Asked by
F_lipe 135
7 years ago

I'm trying to make a simple reload system

So basically what happens is in my main raycast script every time the person clicks to make a raycast it take the value of ammo and subtracts 1 so all that works fine but then I'm running into a issue in another script that is supposed to change the value of ammo back to 10 when it runs out

if script.Parent.Ammo.Value<=0 then
    script.Parent.Ammo.Value=10
end

Here is the main script if you need it:

tool = script.Parent
playerMouse=game.Players.LocalPlayer:GetMouse()
player=game.Players.LocalPlayer

tool.Equipped:connect(function(mouse)
    mouse.Icon="http://www.roblox.com/asset/?id=36983768"
    mouse.Button1Down:connect(function()
        script.Parent.Ammo.Value=script.Parent.Ammo.Value-1
        if script.Parent.Ammo.Value>=1 then
        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.25
        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(1.5)

                end
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

I don't know because you only posted three lines, but it doesn't look like there's a Changed event there. You need to check every time the value changes; as it is now, it only checks once.

script.Parent.Ammo.Changed:connect(function()
    if script.Parent.Ammo.Value<=0 then
        script.Parent.Ammo.Value=10
    end
end)

Hope this helped.

Ad

Answer this question