So in the tutorial level of my game, I want the player to pick up say, a pistol. So I duplicated the pistol and put it into the workspace so that the tool can be picked up.

However, when I equip the tool, the LocalScript controlling the gun breaks.

I don't think I need a script for this, so I won't put up the script.

Does anyone know some sort of function or property that prevents this from happening? Thanks.

EDIT: A lot of you wanted the LocalScript so here you go. (Yes, it's long.)

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
	local MaxAmmo = 9
	local Ammo = MaxAmmo
	
	local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
	while not character do
		character.AncestryChanged:Wait()
	end
	local hum = character:WaitForChild('Humanoid')
	local reloadAnim = hum:LoadAnimation(script.Parent.Animation)
	local fireAnim = hum:LoadAnimation(script.Parent.fire)
	
	
	script.Parent:WaitForChild('MaxAmmo').Value = MaxAmmo
	script.Parent:WaitForChild('Ammo').Value = Ammo
	
	
	local Reloading = false
	local uis = game:GetService("UserInputService")
	script.Parent.Equipped:Connect(function()
		uis.MouseIconEnabled = true
		game.Players.LocalPlayer:GetMouse().Icon = 'rbxassetid://68308747'
	end)
	script.Parent.Unequipped:Connect(function()
		uis.MouseIconEnabled = false
		game.Players.LocalPlayer:GetMouse().Icon = 'rbxassetid://442141180'
	end)
	script.Parent.Activated:Connect(function()
		if Ammo > 0 and not Reloading then
			script.Parent.Handle.fire:Play()
			fireAnim:Play()
			Ammo = Ammo - 1
			script.Parent.Handle.Part.FrontFlash.Transparency = 0
			script.Parent.Handle.Part.BackFlash.Transparency = 0
			wait()
			script.Parent.Handle.Part.FrontFlash.Transparency = 1
			script.Parent.Handle.Part.BackFlash.Transparency = 1
			script.Parent.Handle.BillboardGui.Frame.TextLabel.Text = Ammo.." / "..MaxAmmo
			if game.Players.LocalPlayer:GetMouse().Target.Parent:FindFirstChild('EnemyHum') then
				game.Players.LocalPlayer:GetMouse().Target.Parent:FindFirstChild('EnemyHum'):TakeDamage(26)
			end
		elseif Reloading == false then
			uis.InputBegan:Connect(function(keyCode)
				if keyCode.keyCode == Enum.KeyCode.R then
					if Reloading == false then
						if Ammo <= 0 then
							reloadAnim:Play()
							Reloading = true
							script.Parent.Handle.reload:Play()
							wait(script.Parent.Handle.reload.TimeLength)
							script.Parent.Handle.BillboardGui.Frame.TextLabel.Text = "9 / 9"
							Ammo = MaxAmmo
							Reloading = false
						end
					end
				end
			end)
		end
	end)
	script.Parent.Unequipped:Connect(function()
		Reloading = false
		script.Parent.Handle.reload:Stop()
		reloadAnim:Stop()
	end)
end)

4 comments

0

can we see the localscript

0

Yea.... We need to see the script bud.

0

especially if your LS breaks

0

Fine. It's gonna be long tho. Bear with me.