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

Why will my LocalScript work in Studio but not actual roblox?

Asked by 8 years ago

This is a script that basically just makes some instances and adds velocity to them however it does not work in the actual Roblox game. Pressing X does nothing however in Studio it works fine. I have seen somewhere that I can only use LocalPlayer in my script so I tried to remove most variables referencing LocalPlayer. Here is the code.

Animation = game.StarterPack.LocalScript.Animation
local torso = game.Players.LocalPlayer.Character.Torso
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local plyr = script.Parent.Parent




function gunsummon(key)
    if key == "x" then
        print("gun1")
        local animTrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Animation)
        animTrack:Play()
        wait(1)
        x1 = Instance.new("Part", game.Players.LocalPlayer.Character.Torso)
        x1.Name = "Gun1"
        x2 = Instance.new("Part", game.Players.LocalPlayer.Character.Torso)
        x2.Name = "Gun2"
        x3 = Instance.new("Part", game.Players.LocalPlayer.Character.Torso)
        x3.Name = "Gun3"
        x4 = Instance.new("Part", game.Players.LocalPlayer.Character.Torso)
        x4.Name = "Gun4"
        y1 = Instance.new("SpecialMesh", x1)
        y1.MeshId = "rbxassetid://3835506"
        y2 = Instance.new("SpecialMesh", x2)
        y2.MeshId = "rbxassetid://3835506"
        y3 = Instance.new("SpecialMesh", x3)
        y3.MeshId = "rbxassetid://3835506"
        y4 = Instance.new("SpecialMesh",  x4)
        y4.MeshId = "rbxassetid://3835506"
        x1.BrickColor = BrickColor.new("New Yeller")
        x2.BrickColor = BrickColor.new("New Yeller")
        x3.BrickColor = BrickColor.new("New Yeller")
        x4.BrickColor = BrickColor.new("New Yeller")
        x1.Anchored = true
        x1.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Torso.Position.X,game.Players.LocalPlayer.Character.Torso.Position.Y,game.Players.LocalPlayer.Character.Torso.Position.Z) * CFrame.Angles(0,220,0)
        x1.CanCollide = false
        x2.Anchored = true
        x2.CanCollide = false
        x2.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Torso.Position.X,game.Players.LocalPlayer.Character.Torso.Position.Y,game.Players.LocalPlayer.Character.Torso.Position.Z) *  CFrame.Angles(0,-80,0)
        x3.Anchored = true
        x3.CanCollide = false
        x3.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Torso.Position.X,game.Players.LocalPlayer.Character.Torso.Position.Y,game.Players.LocalPlayer.Character.Torso.Position.Z) *  CFrame.Angles(0,80,0)
        x4.Anchored = true
        x4.CanCollide = false
        x4.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Torso.Position.X,game.Players.LocalPlayer.Character.Torso.Position.Y,game.Players.LocalPlayer.Character.Torso.Position.Z) *  CFrame.Angles(0,110,-0)
        local gunpositioncalc1 = game.Players.LocalPlayer.Character.Torso.Gun1.Position.Z - 10
        x1.Position = Vector3.new(game.Players.LocalPlayer.Character.Torso.Position.X,game.Players.LocalPlayer.Character.Torso.Position.Y,gunpositioncalc1)
        local gunpositioncalc2 = game.Players.LocalPlayer.Character.Torso.Gun2.Position.X - 10
        x2.Position = Vector3.new(gunpositioncalc2,game.Players.LocalPlayer.Character.Torso.Position.Y,game.Players.LocalPlayer.Character.Torso.Position.Z)
        local gunpositioncalc3 = game.Players.LocalPlayer.Character.Torso.Gun3.Position.X - -10
        x3.Position = Vector3.new(gunpositioncalc3,game.Players.LocalPlayer.Character.Torso.Position.Y,game.Players.LocalPlayer.Character.Torso.Position.Z)
        local gunpositioncalc4 = game.Players.LocalPlayer.Character.Torso.Gun3.Position.Z - -10
        x4.Position = Vector3.new(game.Players.LocalPlayer.Character.Torso.Position.X,game.Players.LocalPlayer.Character.Torso.Position.Y,gunpositioncalc4)
        wait(0.5)
        ----------------------------------------------------------------------Bullet 1
        b1 = Instance.new("Part",x1)
        b1.Name = "Bullet1"
        b1.Shape = "Ball"
        b1.TopSurface = "Smooth"
        b1.BrickColor = BrickColor.new("Black")     
        b1.BottomSurface = "Smooth"
        b1.Size = Vector3.new(1,1,1)
        y = Instance.new("BodyVelocity", b1)
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Vector3.new(0,0,-120)
        b1.Position = x1.Position
        ----------------------------------------------------------------------Bullet 2
        b2 = Instance.new("Part",x4)
        b2.Name = "Bullet2"
        b2.Shape = "Ball"
        b2.TopSurface = "Smooth"
        b2.BrickColor = BrickColor.new("Black")     
        b2.BottomSurface = "Smooth"
        b2.Size = Vector3.new(1,1,1)
        y = Instance.new("BodyVelocity", b2)
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Vector3.new(0,0,120)
        b2.Position = x4.Position
        ----------------------------------------------------------------------Bullet 3
        b3 = Instance.new("Part",x3)
        b3.Name = "Bullet3"
        b3.Shape = "Ball"
        b3.TopSurface = "Smooth"
        b3.BrickColor = BrickColor.new("Black")     
        b3.BottomSurface = "Smooth"
        b3.Size = Vector3.new(1,1,1)
        y = Instance.new("BodyVelocity", b3)
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Vector3.new(120,0,0)
        b3.Position = x3.Position
        ----------------------------------------------------------------------Bullet 4
        b4 = Instance.new("Part",x2)
        b4.Name = "Bullet4"
        b4.Shape = "Ball"
        b4.TopSurface = "Smooth"
        b4.BrickColor = BrickColor.new("Black")     
        b4.BottomSurface = "Smooth"
        b4.Size = Vector3.new(1,1,1)
        y = Instance.new("BodyVelocity", b4)
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Vector3.new(-120,0,0)
        b4.Position = x2.Position
        -----------------------------------------------------------------------End
        wait(0.8)
        game.Players.LocalPlayer.Character.Torso.Gun1:Destroy()
        game.Players.LocalPlayer.Character.Torso.Gun2:Destroy()
        game.Players.LocalPlayer.Character.Torso.Gun3:Destroy()
        game.Players.LocalPlayer.Character.Torso.Gun4:Destroy()
        b1:Destroy()
        b2:Destroy()
        b3:Destroy()
        b4:Destroy()


    end
end

mouse.KeyDown:connect(gunsummon)


0
Try pressing the F9 button in a server, try see if there are any errors. Some possibilities could be that the script isn't loading in time, or isn't getting to the client, try putting it in replicated storage dragonkeeper467 453 — 8y
0
I put it in replicated storage and it unfortunately has not fixed anything. GangLemon 0 — 8y

Answer this question