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)
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?!?
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.
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!
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…
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))
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!