I want a system where you activate a special ability using either the text button [Most likely on ipad/phone/consoles] or where PC players press a key for it to activate i got one to work but the other is refusing to work and i have no ideas as to why
this is my code that is having problems:
-- AbilityServer
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
local tool = script.Parent
local cfg = tool:WaitForChild("Config")
-- Remotes
local ShockRE = tool:WaitForChild("AbilityEvent") -- Shockwave (E)
local SlamRE = tool:WaitForChild("GroundSlamEvent") -- Ground Slam (Q)
-- Shockwave config
local RADIUS = cfg:WaitForChild("Radius").Value
local DAMAGE = cfg:WaitForChild("Damage").Value
local KNOCKBACK = cfg:WaitForChild("Knockback").Value
local CD_SHOCK = cfg:WaitForChild("Cooldown").Value
-- Slam config
local SLAM_RADIUS = cfg:WaitForChild("SlamRadius").Value
local SLAM_DAMAGE = cfg:WaitForChild("SlamDamage").Value
local SLAM_STUN = cfg:WaitForChild("SlamStun").Value
local SLAM_UP = cfg:WaitForChild("SlamUpForce").Value
local SLAM_DELAY = cfg:WaitForChild("SlamDelay").Value
local CD_SLAM = cfg:WaitForChild("SlamCooldown").Value
-- Cash
local REWARD = cfg:WaitForChild("KillReward").Value
local lastShock, lastSlam = {}, {}
-- Helpers -------------------------------------------------------
local function addCash(plr, amt)
local ls = plr:FindFirstChild("leaderstats")
local cash = ls and ls:FindFirstChild("Cash")
if cash then cash.Value += amt end
end
local function awardKill(plr) if plr then addCash(plr, REWARD) end end
local function tagHum(h, killer)
local tag = h:FindFirstChild("KillerTag")
if not tag then
tag = Instance.new("ObjectValue")
tag.Name = "KillerTag"
tag.Parent = h
h.Died:Connect(function()
if tag.Value then awardKill(tag.Value) end
tag:Destroy()
end)
Debris:AddItem(tag, 8)
end
tag.Value = killer
end
local function ring(cf, size)
local p = Instance.new("Part")
p.Anchored, p.CanCollide = true, false
p.Material = Enum.Material.Neon
p.Color = Color3.new(1,1,1)
p.Transparency = 0.5
p.Size = Vector3.new(1,0.2,1)
p.CFrame = cf
Instance.new("CylinderMesh", p)
p.Parent = workspace
TweenService:Create(p, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{Size = Vector3.new(size*2,0.2,size*2), Transparency = 0.2}):Play()
task.delay(0.25, function()
TweenService:Create(p, TweenInfo.new(0.15), {Transparency = 1}):Play()
task.delay(0.15, function() p:Destroy() end)
end)
end
local function hitHumanoids(originPos, r, ignoreChar, damage, killer, extraFn)
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {ignoreChar}
local hit = {}
for _, part in ipairs(workspace:GetPartBoundsInRadius(originPos, r, params)) do
local hum = part.Parent and part.Parent:FindFirstChildOfClass("Humanoid")
if hum and hum.Health > 0 and not hit[hum] then
hit[hum] = true
tagHum(hum, killer)
local oldHP = hum.Health
if damage > 0 then hum:TakeDamage(damage) end
if oldHP > 0 and oldHP - damage <= 0 then awardKill(killer) end
if extraFn then extraFn(hum) end
end
end
end
-- ---------------------------------------------------------------
-- Shockwave (E)
ShockRE.OnServerEvent:Connect(function(plr)
local now = os.clock()
if lastShock[plr] and now - lastShock[plr] < CD_SHOCK then return end
lastShock[plr] = now
local char = plr.Character
local root = char and char:FindFirstChild("HumanoidRootPart")
if not root then return end
ring(root.CFrame, RADIUS)
hitHumanoids(root.Position, RADIUS, char, DAMAGE, plr, function(h)
local er = h.Parent:FindFirstChild("HumanoidRootPart")
if er then
local dir = (er.Position - root.Position).Unit
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(1e6,1e6,1e6)
bv.Velocity = dir * KNOCKBACK + Vector3.new(0,20,0)
bv.Parent = er
Debris:AddItem(bv, 0.25)
end
end)
end)
-- Ground Slam (Q) with landing detection
local function stun(h, secs)
local ws, jp = h.WalkSpeed, h.JumpPower
h.WalkSpeed, h.JumpPower = 0, 0
task.delay(secs, function()
if h and h.Parent then
h.WalkSpeed, h.JumpPower = ws, jp
end
end)
end
SlamRE.OnServerEvent:Connect(function(plr)
local now = os.clock()
if lastSlam[plr] and now - lastSlam[plr] < CD_SLAM then return end
lastSlam[plr] = now
local char = plr.Character
local root = char and char:FindFirstChild("HumanoidRootPart")
local hum = char and char:FindFirstChildOfClass("Humanoid")
if not root or not hum then return end
-- launch up
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(1e6,1e6,1e6)
bv.Velocity = Vector3.new(0, SLAM_UP, 0)
bv.Parent = root
Debris:AddItem(bv, 0.25)
-- minimum air time
task.wait(SLAM_DELAY)
-- wait for landing or timeout
local landed = false
local timeout = 1.5
local t0 = os.clock()
local stateConn
stateConn = hum.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Landed
or newState == Enum.HumanoidStateType.Running
or newState == Enum.HumanoidStateType.RunningNoPhysics then
landed = true
end
end)
while not landed and os.clock() - t0 < timeout do
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
local hit = workspace:Raycast(root.Position, Vector3.new(0,-6,0), params)
if hit then landed = true break end
RunService.Heartbeat:Wait()
end
if stateConn then stateConn:Disconnect() end
-- impact
local slamPos = root.Position
ring(root.CFrame, SLAM_RADIUS)
hitHumanoids(slamPos, SLAM_RADIUS, char, SLAM_DAMAGE, plr, function(h)
stun(h, SLAM_STUN)
local er = h.Parent:FindFirstChild("HumanoidRootPart")
if er then
local dir = (er.Position - slamPos).Unit
local kb = Instance.new("BodyVelocity")
kb.MaxForce = Vector3.new(1e6,1e6,1e6)
kb.Velocity = dir * 30 + Vector3.new(0,35,0)
kb.Parent = er
Debris:AddItem(kb, 0.25)
end
end)
end)
If you have any questions feel free to ask below
