I put this code in a script because I'm animating a r15 viewmodel for my fps and it works in studio but not in game. This code is in a normal script too. sorry I have to drag out the title but anyway here is the script.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
local reloading = false
local sprinting = false
local controller = Instance.new("AnimationController")
controller.Parent = script.Parent
local idle = controller:LoadAnimation(script.Parent.Idle)
local shoot = controller:LoadAnimation(script.Parent.Shoot)
local reload = controller:LoadAnimation(script.Parent.Reload)
local sprint = controller:LoadAnimation(script.Parent.Sprint)
idle.Looped = true
shoot.Looped = false
reload.Looped = false
sprint.Looped = true
idle:Play()
shootsound = script.Parent.Fire2:Clone()
mouse.Button1Down:connect(function()
if reloading == false then
local shootsound = script.Parent.Fire2:Clone()
shootsound.Parent = script.Parent
shootsound.MaxDistance = 500
shootsound.Volume = 0.3
shoot:Play()
script.Parent.M1911.Flash.SparkFX.Enabled = true
script.Parent.M1911.Flash.Flash.Enabled = true
shootsound.Playing = true
wait(.5)
script.Parent.M1911.Flash.SparkFX.Enabled = false
script.Parent.M1911.Flash.Flash.Enabled = false
game.Debris:AddItem(shootsound,3)
idle:Play()
end
end)
uis.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
if reloading == false then
reloading = true
idle:Stop()
reload:Play()
script.Parent.Mag:Play()
wait(1.5)
reloading = false
idle:Play()
end
end
end)
uis.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if reloading == false then
idle.Looped = false
sprint:Play()
sprint.Looped = true
player.Character.Humanoid.WalkSpeed = 24
end
end
end)
uis.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if reloading == false then
sprint.Looped = false
idle:Play()
idle.Looped = true
player.Character.Humanoid.WalkSpeed = 16
end
end
end)
this is a long script but I don't know why it won't work in game please help.

7 comments
Tab your code
how does that help? @Goulstem
Organized and easier to read, makes helping a lot easier.
so you want be to repost this but easier to read correct?
I noticed you said you put it in a script. Is this a normal or localscript?
This is in a normal script
You can edit a post, y'know.