Local Script working on mobile but not working on pc? Help, this is so weird!

Hi guys!

So today i’m making a game called Survival Unarmed! It is a zombie game, and it has a bottle of heal. For some reason, the local script inside of it is not working on pc, but on mobile, that is so weird, here is the code:

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Tool = script.Parent

local DrinkAnimation = Tool:WaitForChild("Drink")
local DrinkTrack = Humanoid:LoadAnimation(DrinkAnimation)

local IsDrinking = false
local Drinks = 5

Tool.Activated:Connect(function()
	if IsDrinking == false then
		IsDrinking = true
		Drinks -= 1
		print(Drinks)
		DrinkTrack:Play()
		DrinkTrack.Stopped:Connect(function()
			Humanoid.Health += 30
		end)
		task.wait(2.7)
		IsDrinking = false
		if Drinks <= 0 then
			IsDrinking = false
			Tool:Destroy()
		end
	end
end)
2 Likes

What do you mean by its not working, like it won’t do anything?

3 Likes

Yes, exactly, it for some reason, doesn’t do anything, it doesn’t print, nothing! But this happens only on pc, but not on mobile, this is so weird, why is that happening?!?

2 Likes

The problem is probably that the activated function only works on pc because of the mouse click, I think you have to do something else for mobile, maybe make a button for them, or replace the tool.Activated with something else.

2 Likes

What did i just said? IT IS NOT WORKING ON PC!!! ON MOBILE IT WORKS FINE, BUT THE PC IS THE OPPOSITE, IT DOESN’T WORK!!! oh sorry i was a bit angry anyways, that’s what is happening!

2 Likes

bro got aggressive :skull:

so if you changed the scripy to “print(“Hello world!”)” it like wouldnt print?

2 Likes

Oh lol I didn’t realise, that’s very weird

3 Likes

that’s not what i mean, all the other code part is working fine, this specific part is not working:

Tool.Activated:Connect(function()
	if IsDrinking == false then
		IsDrinking = true
		Drinks -= 1
		print(Drinks)
		DrinkTrack:Play()
		DrinkTrack.Stopped:Connect(function()
			Humanoid.Health += 30
		end)
		task.wait(2.7)
		IsDrinking = false
		if Drinks <= 0 then
			IsDrinking = false
			Tool:Destroy()
		end
	end
end)
1 Like

I know right? That’s why i need help, that’s so weird!

1 Like

prolly has somthing to do with .activaed

change it to equipped then detect like a tap or a click maybe?

2 Likes

Im not sure, probably has something to do with the debounce.

2 Likes

On my other games activated function worked fine, idk why it isn’t working now :confused: but i can try anyways…

2 Likes

How? Does it only applies the debounce to mobile but not pc? that is weird

2 Likes

Then Im at a loss, Im not sure about this. Might as well boost.

2 Likes

I’m trying a thing, not sure if it will work or not

2 Likes

Wait what??? I think i found the problem, the combat manager which is a combat script of mine here, is making it have a conflict i think i have found the problem! Now i need help of how to fix it…

2 Likes

How is it conflicting?

char1234

2 Likes

It uses the mouse button 1 function, i think it like… cancels out the activated function, i found a problem with context action service! Anyways, here’s the script:

-- Get the local player character and humanoid
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
-- Get the mouse
local Mouse = Player:GetMouse()

local HitboxModule = require(game.ReplicatedStorage.Modules:WaitForChild("RaycastHitboxV4"))

-- Wait for the RemoteFunction
local RemoteFunction = script:WaitForChild("RemoteFunction")
local Animations = game.ReplicatedStorage:WaitForChild("Anims")

local ParryAnimation = Humanoid:LoadAnimation(Animations.Parry)
local ParryCooldown = 10

local M1Debounce = false
local ParryDebounce = false
local CanParry = true

-- Make a combo variable
local Combo = 1

local ContextActionService = game:GetService("ContextActionService")
local UIS = game:GetService("UserInputService")

-- Function to handle the attack
local function handleParry()
	-- Check if the player has an active weapon
	if Player.Character.ActiveWeapon:GetChildren()[1] and M1Debounce == false and ParryDebounce == false and CanParry == true then
		-- Invoke the remote function to get the result
		local Weapon = Player.Character.ActiveWeapon:GetChildren()[1]
		CanParry = false
		task.delay(ParryCooldown, function()
			CanParry = true
		end)
		ParryDebounce = true
		RemoteFunction:InvokeServer("Parry")
		ParryAnimation:Play()
		task.wait(1)
		ParryDebounce = false
		RemoteFunction:InvokeServer("Unparry")
	end
end

-- Connect the handleAttack function to the mouse button down event

ContextActionService:BindAction("Parry", handleParry, true, Enum.KeyCode.F)

ContextActionService:SetImage("Parry", "rbxassetid://11322093465")
ContextActionService:SetPosition("Parry", UDim2.new(0.1, 0, 0.1, 0))

-- Function to handle the attack
local function handleAttack()
	-- Check if the player has an active weapon
	if Player.Character.ActiveWeapon:GetChildren()[1] and M1Debounce == false and ParryDebounce == false then
		-- Invoke the remote function to get the result
		local Weapon = Player.Character.ActiveWeapon:GetChildren()[1]
		M1Debounce = true
		RemoteFunction:InvokeServer("PlaySwing")
		-- If the result is true, perform the attack

		task.delay(0.5, function()
			M1Debounce = false
		end)
		local CorrespondingM1Anim = Animations:FindFirstChild("M1_"..Combo)
		if CorrespondingM1Anim then
			local AnimationTrack = Humanoid:LoadAnimation(CorrespondingM1Anim)
			local NewHitbox = HitboxModule.new(Weapon)
			NewHitbox.Visualizer = true
			NewHitbox.RaycastParams = RaycastParams.new()
			NewHitbox.RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
			NewHitbox.RaycastParams.FilterDescendantsInstances = {Character}
			NewHitbox.OnHit:Connect(function(hit, hithum)
				local Player = game.Players:GetPlayerFromCharacter(hithum.Parent)
				if not Player then
					local HitAnimation = hithum:LoadAnimation(Animations:FindFirstChild("Hit_"..Combo))
					RemoteFunction:InvokeServer("Damage", hithum)
					RemoteFunction:InvokeServer("PlayHit")
					HitAnimation:Play()
				else
					print("current target was a player")
				end
			end)
			NewHitbox:HitStart()
			task.delay(0.35, function()
				NewHitbox:HitStop()
			end)
			AnimationTrack:Play()
		end
		Combo = Combo + 1
		local OldCombo = Combo
		task.delay(1, function()
			if OldCombo == Combo then
				Combo = 1
			end
		end)
		if Combo > 4 then
			Combo = 1
		end
		print("Attack performed")

	end
end

-- Connect the handleAttack function to the mouse button down event
ContextActionService:BindAction("Attack", handleAttack, true, Enum.UserInputType.MouseButton1)

ContextActionService:SetImage("Attack", "rbxassetid://7485051715")
ContextActionService:SetPosition("Attack", UDim2.new(0.1, 0, -0.2, 0))
2 Likes

ContextActionService:BindAction(“Attack”, handleAttack, true, Enum.UserInputType.MouseButton2)

You can use a quick debug test here. Rebind it to right click just for now. Then test your tool if it works on PC then you know it is that line of code causing it. Since mobile cannot click i assume thats why the tool works there and not on PC. Test this out and get back to me!

3 Likes

Now that’s a problem, when i put it on mousebutton2 i can’t move my camera, context action service is bugged! But that is what happens.

2 Likes