Guns have a crosshair/cursor in studio testing, but not when ingame

would anyone have a solution to this? the guns are from toolbox, and work fine in studio testing, but there is just the normal mouse ingame

Could you perhaps attach some code

Yeah, i forgot to do that as im about to fall asleep. Ill send a reply/update tmrw. Not rlly sure exactly what to send tho, as it works fine in studio

local MOUSE_ICON = ‘rbxasset://textures/GunCursor.png’
local RELOADING_ICON = ‘rbxasset://textures/GunWaitCursor.png’

local Players = game:GetService(“Players”)
local UserInputService = game:GetService(“UserInputService”)
local Tool = script.Parent
local toolammo = Tool:WaitForChild(“CurrentAmmo”)
local toolrecoil = Tool:WaitForChild(“CurrentRecoil”)
local firefunction = Tool.fire
local reloadfunction = Tool.reload
local animatefunction = Tool.animate
local crouchfunction = Tool.crouch
local meleefunction = Tool.melee
local hitmarkerfunction = Tool.hitmarker
local hitmarkerframes = 0
local hitmarkerframesmax = 3
local storedhuman = nil
local idleanim = Tool.Idle
local idleanimr15 = Tool.IdleR15
local loadedidle = nil
local shootanim = Tool.Shoot
local shootanimr15 = Tool.ShootR15
local loadedshoot = nil
local crouchanim = Tool.Crouch
local crouchanimr15 = Tool.CrouchR15
local loadedcrouch = nil
local meleeanim = Tool.MeleeA
local meleeanimr15 = Tool.MeleeAR15
local loadedmelee = nil
local zoomed = false
local equipped = false

AmmoDisplay = script:WaitForChild(“AmmoDisplay”):Clone()
AmmoDisplayClone = nil

local Mouse = nil

local function AdjustAmmoDisplay()
local Frame = AmmoDisplayClone.Frame
local Ammo = Frame.Ammo
Ammo.AmmoCounter.CounterPart.Text = toolammo.Value
end

local function UpdateIcon()
if Mouse then
–Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
–Mouse.Icon = MOUSE_ICON
Mouse.Icon = toolammo.Value>0 and MOUSE_ICON or RELOADING_ICON
end
end

local function UpdateHitmarker()
hitmarkerframes=hitmarkerframesmax
if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild(‘Crosshair’) and Mouse then
AmmoDisplayClone.Crosshair.Hitmarker:Play()
end
end

local function OnEquipped(mouse)
equipped=true
local Character = Tool.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local PlayerGui = Player:FindFirstChild(“PlayerGui”)
if PlayerGui then
AmmoDisplayClone = AmmoDisplay:Clone()
AdjustAmmoDisplay()
AmmoDisplayClone.Parent = PlayerGui
end
local humanoid = Character:FindFirstChild(“Humanoid”)
if humanoid then
storedhuman = humanoid
end

if loadedidle==nil then
	if storedhuman.RigType==Enum.HumanoidRigType.R15 then
		loadedidle = humanoid:LoadAnimation(idleanimr15)
	else
		loadedidle = humanoid:LoadAnimation(idleanim)
	end
	loadedidle.Priority = Enum.AnimationPriority.Movement
	loadedidle.Looped = true
end
if loadedshoot==nil then
	if storedhuman.RigType==Enum.HumanoidRigType.R15 then
		loadedshoot = humanoid:LoadAnimation(shootanimr15)
	else
		loadedshoot = humanoid:LoadAnimation(shootanim)
	end
	loadedshoot.Priority = Enum.AnimationPriority.Action
end
if loadedcrouch==nil then
	if storedhuman.RigType==Enum.HumanoidRigType.R15 then
		loadedcrouch = humanoid:LoadAnimation(crouchanimr15)
	else
		loadedcrouch = humanoid:LoadAnimation(crouchanim)
	end
	loadedcrouch.Priority = Enum.AnimationPriority.Movement
	loadedcrouch.Looped = true
end
if loadedmelee==nil then
	if storedhuman.RigType==Enum.HumanoidRigType.R15 then
		loadedmelee = humanoid:LoadAnimation(meleeanimr15)
	else
		loadedmelee = humanoid:LoadAnimation(meleeanim)
	end
	loadedmelee.Priority = Enum.AnimationPriority.Action
end
loadedidle:Play()
fanim(1)
Mouse = mouse
UserInputService.MouseIconEnabled=false
UpdateIcon()

end

local function OnChanged(property)
if property == ‘Enabled’ then
UpdateIcon()
end
end

function Unequipped()
equipped=false
AmmoDisplayClone:Destroy()
UserInputService.MouseIconEnabled=true
loadedidle:Stop()
loadedshoot:Stop()
loadedcrouch:Stop()
loadedmelee:Stop()
workspace.CurrentCamera.FieldOfView = 70
zoomed = false
fanim(3)
end

Tool.Equipped:connect(OnEquipped)
Tool.Changed:connect(OnChanged)
Tool.Unequipped:connect(Unequipped)

handle = Tool.Handle
mouse = game.Players.LocalPlayer:GetMouse()
local UserInputService = game:GetService(“UserInputService”)
local pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)

colors = {45, 119, 21, 24, 23, 105, 104}

function fire(v)
firefunction:FireServer(v)
end

function reload()
reloadfunction:FireServer()
end

function fanim(v)
animatefunction:FireServer(v)
end

function crouch()
crouchfunction:FireServer()
end

function melee()
meleefunction:FireServer()
end

local function checkhumanoid()
local character = Tool.Parent;
local humanoid = character:FindFirstChild(“Humanoid”)
if humanoid then
storedhuman = humanoid
return true
end
if humanoid == nil then
–print(“Humanoid not found”)
return false
elseif humanoid.Health<=0 then
–print(“u are ded not big surprise”)
return false
end
end

local function onInputBegan(input, gameProcessed)
if not checkhumanoid() then
return
end
–if input.UserInputType == Enum.UserInputType.MouseButton2 then
– delay(0, function()
– while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) do
– wait()
– workspace.CurrentCamera.FieldOfView = 30
– end
– workspace.CurrentCamera.FieldOfView = 70
– end)
–end
if input.UserInputType == Enum.UserInputType.Keyboard then
if UserInputService:IsKeyDown(Enum.KeyCode.R) then
reload()
end
if UserInputService:IsKeyDown(Enum.KeyCode.C) then
crouch()
end
if UserInputService:IsKeyDown(Enum.KeyCode.E) then
if not zoomed then
zoomed = true
workspace.CurrentCamera.FieldOfView = 50
else
zoomed = false
workspace.CurrentCamera.FieldOfView = 70
end
end
if UserInputService:IsKeyDown(Enum.KeyCode.V) then
melee()
end
end
end

script.Parent:WaitForChild(“animate”).OnClientEvent:Connect(function(id)
if not checkhumanoid() then
return
end
if id==1 then
loadedidle:Stop()
loadedcrouch:Play()
end
if id==2 then
loadedidle:Play()
loadedcrouch:Stop()
end
end)

script.Parent:WaitForChild(“melee”).OnClientEvent:Connect(function(id)
if not checkhumanoid() then
return
end
if id==1 then
loadedmelee:Play()
end
end)

script.Parent:WaitForChild(“reload”).OnClientEvent:Connect(function(id)
if not checkhumanoid() then
return
end
AdjustAmmoDisplay()
if id==1 then
if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild(‘Crosshair’) then
if AmmoDisplayClone.Crosshair:FindFirstChild(‘ReloadingLabel’) then
AmmoDisplayClone.Crosshair.ReloadingLabel.Visible = true
end
end
end
if id==2 then
if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild(‘Crosshair’) then
if AmmoDisplayClone.Crosshair:FindFirstChild(‘ReloadingLabel’) then
AmmoDisplayClone.Crosshair.ReloadingLabel.Visible = false
end
end
end
end)

script.Parent:WaitForChild(“fire”).OnClientEvent:Connect(function(id)
if not checkhumanoid() then
return
end
if id==1 then
UpdateIcon()
AdjustAmmoDisplay()
end
end)

script.Parent:WaitForChild(“hitmarker”).OnClientEvent:Connect(function(id)
if id==1 then
UpdateHitmarker()
end
end)

Tool.Enabled = true
function onActivated()

if not Tool.Enabled then
	return
end
pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
while pressed and equipped do
	pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
	if pressed then
		Tool.Enabled = false

		local character = Tool.Parent;
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			storedhuman = humanoid
		end
		if humanoid == nil then
			--print("Humanoid not found")
			return
		elseif humanoid.Health<=0 then
			--print("u are ded not big surprise")
			return
		end

		local targetPos = humanoid.TargetPoint
		local lookAt = (mouse.Hit.p - handle.Position).unit

		--fanim(2)
		fire(lookAt)

		wait(.123)

		Tool.Enabled = true
	end
end

end

script.Parent.Activated:connect(onActivated)
UserInputService.InputBegan:Connect(onInputBegan)

while true do
wait()
if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild(‘Crosshair’) and Mouse then
AmmoDisplayClone.Crosshair.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
local absoluteY = 650
AmmoDisplayClone.Crosshair:TweenSize(
UDim2.new(0, toolrecoil.Value/10000 * absoluteY * 2 + 23, 0, toolrecoil.Value/10000 * absoluteY * 2 + 23),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
0)
if AmmoDisplayClone.Crosshair:FindFirstChild(‘TargetHitImage’) then
if hitmarkerframes>0 then
AmmoDisplayClone.Crosshair.TargetHitImage.Visible=true
AmmoDisplayClone.Crosshair.TargetHitImage.ImageTransparency=1-(hitmarkerframes/hitmarkerframesmax)
hitmarkerframes-=1
else
AmmoDisplayClone.Crosshair.TargetHitImage.Visible=false
end
end
end
end

–while true do
– wait()
– pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
– if pressed==true then
– if not Tool.Enabled then
– return
– end

– Tool.Enabled = false

– local character = Tool.Parent
– local humanoid
– if character then
– humanoid = character.Humanoid
– end

– if humanoid then
– local targetPos = humanoid.TargetPoint
– local lookAt = (mouse.Hit.p - character.Head.Position).unit

– fire(lookAt)

– wait(.5)
– end
– Tool.Enabled = true
– end
– print(pressed)
–end
this is the script of one of the offenders. it works fien in studio test but not in the actual game

1 Like