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

Why is this script working in play solo mode but not in server?

Asked by 10 years ago

So this is where the script is set at: Pistol(Tool) > LocalScript

Script:

Player = game.Players.LocalPlayer
Gun = script.Parent --Tool(Pistol)
Ammo = Gun.ammo.Value -- there is an intvalue called ammo and it value is set at 10
Clips = Gun.clips.Value -- then is an invalue call clips andit value is set at 2
mouse = Player:GetMouse()
BulletDamage = 10
enabled = true

function onEquippedLocal()
    Player.PlayerGui.GunGui.FrameforGun.Visible = true
end
function unEquippedLocal()
    Player.PlayerGui.GunGui.FrameforGun.Visible = false
end
Gun.Unequipped:connect(unEquippedLocal)
Gun.Equipped:connect(onEquippedLocal)
function Shoot()
    if Ammo >= 1 and enabled == true then
        enabled = false
        IsFiring = true
        Firing()
    end
end

function Firing()
    repeat wait(0.2)

        function Damage(Part)
            if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.Name == "Zombie" then
                Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -BulletDamage
                Bullet:Destroy()
            end
        end
        Ammo = Ammo -1
        Player.PlayerGui.GunGui.FrameforGun.NumberLabel.Text = ""..Ammo
        enabled = false
        Bullet = Instance.new("Part", Workspace)
        Gun.GripPos = Vector3.new(0,0.3,0)
        game.Debris:AddItem(Bullet,2)
        Bullet.Shape = "Ball"
        Bullet.Size = Vector3.new(0.1,0.1,0.1)
        Bullet.TopSurface = "Smooth"
        Bullet.BottomSurface = "Smooth"
        Bullet.BrickColor = BrickColor.new("Really black")
        Bullet.CanCollide = false
        Bullet.CFrame = Gun.Handle.CFrame
        Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)
        BM = Instance.new("SpecialMesh",Bullet)
        BM.MeshType = "Sphere"
        BM.Scale = Vector3.new(0.2,0.2,0.2)
        v = Instance.new("BodyVelocity", Bullet)
        v.velocity = Bullet.CFrame.lookVector *90
        v.maxForce = Vector3.new(math.huge,math.huge,math.huge)
        Fire = Instance.new("Sound", Bullet)
        Fire.SoundId = "http://www.roblox.com/asset/?id=131419157"
        RP = math.random(10,20)
        RP = RP/10
        Fire.Pitch = RP
        RV = math.random(70,90)
        RV = RV/10
        Fire.Volume = RV
        Fire:Play()
        game.Debris:AddItem(Fire, 2)
        Bullet.Touched:connect(Damage)
        wait()
        Gun.GripPos = Vector3.new(0,0,0)
        enabled = true

    until IsFiring == false or Ammo == 0
end
function StopShooting()
    IsFiring = false
end

function Reload()
    if enabled == true and Ammo < 20  then
        enabled = false
        if Ammo == 0  then
            wait()
            Player.PlayerGui.GunGui.FrameforGun.Reloading.Visible = true
            wait(0.7)
            Player.PlayerGui.GunGui.FrameforGun.Reloading.Visible = false
            Ammo = Ammo +10
            Player.PlayerGui.GunGui.FrameforGun.NumberLabel.Text = ""..Ammo
            Clips = Clips -1
            Player.PlayerGui.GunGui.FrameforGun.NumerLabel.Text = ""..Clips

            if Clips == 0 then
                Ammo = Ammo -10
                Player.PlayerGui.GunGui.FrameforGun.NumberLabel.Text = ""..Ammo
                 Player.PlayerGui.GunGui.FrameforGun.Reloading.Visible = false
                script.Disabled = true
            end
        end 
        enabled = true
    end
end
mouse.KeyDown:connect(Reload)
Gun.Deactivated:connect(StopShooting)
Gun.Activated:connect(Shoot)

Thanks for helping! My error is: 07:46:28.975 - ammo is not a valid member of Tool 07:46:28.975 - Script 'Players.Player1.Backpack.Pistol.LocalScript', Line 3

1 answer

Log in to vote
1
Answered by
jav2612 180
10 years ago

Sometimes when I have an issue with scripts working in solo/test mode but not in a normal server I switch script types and that sometimes fixes it depending on the situation. However since you have an error you can try this:


Player = game.Players.LocalPlayer Gun = script.Parent --Tool(Pistol) Ammo = Gun:FindFirstChild("ammo") if Ammo ~= nil then print("Ammo exists in script.Parent") Ammo = Ammo.Value else print("Ammo does not exist in script.Parent") end

Hopefully that will show you if for some reason the 'ammo' object is not where the script thinks it is. Make sure it's not capitalized or anything and that you've given the correct path.

0
now it says Ammo does not exist in script.Parent killaman922 10 — 10y
0
That means exactly what it said then. For some reason what your looking for doesn't exist. It may be getting removed for some reason by another script. The problem is not within this script but the fact that script.Parent.ammo doesn't exist. jav2612 180 — 10y
Ad

Answer this question