Ability in my game does not work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am creating some scripts where you use a ability with a cooldown (which already works, I used it before) which create a box area with an effect around the player while they play an animation and sound effect, and when someone touches the box besides the user using the tool, it makes an image cover their screen and a mini image hover over their head until the image fades out naturally or they die, currently I am using the script as a serverscriptstorage version.

  2. What is the issue? Include screenshots / videos if possible!
    The script does not work at all, before it worked between studio and a live game, where it would semi work but still be very bugged in studio and not work at all in a live game, I eventually made it to the point where it didn’t work between both of them, the script and their uses will be included.

Server Script in tool or serverscriptservice:

-- Script in ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

-- Remotes
local activateEvent = ReplicatedStorage:WaitForChild("ActivateAbilityEvent")
local fadeRemote = ReplicatedStorage:WaitForChild("ClientFadeEvent")
local markVictimsRemote = ReplicatedStorage:WaitForChild("ClientMarkVictimsAboveHead")

-- Config
local BOX_SIZE = Vector3.new(25, 25, 25)
local PARTICLE_TEXTURE = "rbxassetid://11199270611"
local EFFECT_COLOR = Color3.fromRGB(170, 0, 255)

local FULLSCREEN_IMAGE_ID = "rbxassetid://15647227738"
local BILLBOARD_IMAGE_ID = "rbxassetid://1243374081"

local ANIMATION_ID = "rbxassetid://71473072171116"
local SOUND_ID = "rbxassetid://107594885257092"

local GUI_HOLD = 6
local GUI_FADE = 2
local GUI_TOTAL = GUI_HOLD + GUI_FADE

-- Helpers
local function ensureAnimator(humanoid)
	local animator = humanoid:FindFirstChildOfClass("Animator")
	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end
	return animator
end

local function getAnimLength(track)
	local ok, len = pcall(function() return track:GetTimeLength() end)
	return (ok and len and len > 0) and len or 6
end

local function createEffectBox(cf)
	local part = Instance.new("Part")
	part.Size = BOX_SIZE
	part.CFrame = cf
	part.Anchored = true
	part.CanCollide = false
	part.Transparency = 1
	part.Name = "AbilityBox"
	part.Parent = Workspace

	local emitter = Instance.new("ParticleEmitter")
	emitter.Texture = PARTICLE_TEXTURE
	emitter.Color = ColorSequence.new(EFFECT_COLOR)
	emitter.Speed = NumberRange.new(0, 0)
	emitter.Lifetime = NumberRange.new(0.6)
	emitter.Rate = 80
	emitter.LightEmission = 1
	emitter.Size = NumberSequence.new(4)
	emitter.Parent = part
	emitter:Emit(50)

	return part
end

local function getVictims(cf, size, caster)
	local params = OverlapParams.new()
	params.FilterType = Enum.PartFilterType.Blacklist
	params.FilterDescendantsInstances = {caster.Character}
	local parts = Workspace:GetPartBoundsInBox(cf, size, params)

	local victims, seen = {}, {}
	for _, p in ipairs(parts) do
		local model = p:FindFirstAncestorOfClass("Model")
		if model and not seen[model] then
			seen[model] = true
			local hum = model:FindFirstChildOfClass("Humanoid")
			local root = model:FindFirstChild("HumanoidRootPart")
			if hum and root and hum.Health > 0 then
				local plr = Players:GetPlayerFromCharacter(model)
				if plr and plr ~= caster then
					table.insert(victims, plr)
				end
			end
		end
	end
	return victims
end

-- Ability activation
local function runAbility(player)
	local char = player.Character
	if not char then return end
	local hum = char:FindFirstChildOfClass("Humanoid")
	local root = char:FindFirstChild("HumanoidRootPart")
	if not hum or not root then return end

	if char:GetAttribute("Busy") then return end
	char:SetAttribute("Busy", true)

	root.Anchored = true

	-- Play animation
	local animator = ensureAnimator(hum)
	local anim = Instance.new("Animation")
	anim.AnimationId = ANIMATION_ID
	local track = animator:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track:Play()
	local duration = getAnimLength(track)

	-- Play sound
	local sound = Instance.new("Sound")
	sound.SoundId = SOUND_ID
	sound.Volume = 1
	sound.Parent = root
	sound:Play()
	Debris:AddItem(sound, 10)

	-- Effect box
	local box = createEffectBox(root.CFrame)
	Debris:AddItem(box, duration + 0.2)

	-- Continuous victim detection
	local affected = {}
	local start = os.clock()
	while os.clock() - start < duration and hum.Health > 0 do
		box.CFrame = root.CFrame
		for _, v in ipairs(getVictims(box.CFrame, BOX_SIZE, player)) do
			if not affected[v.UserId] then
				affected[v.UserId] = true
				fadeRemote:FireClient(v, FULLSCREEN_IMAGE_ID, GUI_HOLD, GUI_FADE)
				markVictimsRemote:FireAllClients({v.UserId}, BILLBOARD_IMAGE_ID, GUI_TOTAL)
			end
		end
		RunService.Heartbeat:Wait()
	end

	if box then box:Destroy() end
	root.Anchored = false
	char:SetAttribute("Busy", nil)
end

-- Bind
activateEvent.OnServerEvent:Connect(runAbility)

Localscript in StarterPlayer:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local localPlayer = Players.LocalPlayer

local fadeRemote = ReplicatedStorage:WaitForChild("ClientFadeEvent")
local markVictimsRemote = ReplicatedStorage:WaitForChild("ClientMarkVictimsAboveHead")

-- Fullscreen GUI
fadeRemote.OnClientEvent:Connect(function(imageId, hold, fade)
	local gui = Instance.new("ScreenGui")
	gui.IgnoreGuiInset = true
	gui.ResetOnSpawn = false
	gui.Name = "JumpScareGUI"
	gui.Parent = localPlayer:WaitForChild("PlayerGui")

	local image = Instance.new("ImageLabel")
	image.BackgroundTransparency = 1
	image.Size = UDim2.new(1, 0, 1, 0)
	image.ImageTransparency = 0
	image.Image = imageId
	image.ScaleType = Enum.ScaleType.Stretch
	image.Parent = gui

	task.wait(hold)
	local tween = TweenService:Create(image, TweenInfo.new(fade), {ImageTransparency = 1})
	tween:Play()
	tween.Completed:Wait()
	gui:Destroy()
end)

-- Billboard above victims
local active = {}
markVictimsRemote.OnClientEvent:Connect(function(userIds, imageId, lifespan)
	for _, uid in ipairs(userIds) do
		local plr = Players:GetPlayerByUserId(uid)
		if plr and plr.Character then
			local head = plr.Character:FindFirstChild("Head")
			if head then
				if active[uid] then active[uid]:Destroy() end
				local bb = Instance.new("BillboardGui")
				bb.Size = UDim2.new(0, 300, 0, 300)
				bb.StudsOffset = Vector3.new(0, 4, 0)
				bb.AlwaysOnTop = true
				bb.Parent = head
				local img = Instance.new("ImageLabel")
				img.BackgroundTransparency = 1
				img.Size = UDim2.new(1, 0, 1, 0)
				img.Image = imageId
				img.Parent = bb
				active[uid] = bb
				local hum = plr.Character:FindFirstChildOfClass("Humanoid")
				if hum then
					hum.Died:Connect(function()
						if active[uid] then active[uid]:Destroy() active[uid] = nil end
					end)
				end
				task.delay(lifespan, function()
					if active[uid] then active[uid]:Destroy() active[uid] = nil end
				end)
			end
		end
	end
end)
  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I asked AI for help, I tried using serverscriptservice and the server script in the tool, but nothing has worked.

When you say, “does not work at all”, what do you mean? The script doesn’t achieve the intended affect to any degree? Initial raycasts don’t work? You need to be specific. Also, when you post large blocks of code, you’re likely to not get any help on devForum as many people don’t have/want to spend a large amount of time trying to decipher what specific functions do and how you use them. Try to bugfix first using some prints and seeing where code is being successfully executed and where it is not, then come back to devForum with an issue that’s more narrowed down. If you do have a narrowed down issue, please tell me and I can help!

it doesnt run anything inside of it for some reason
also prints didnt run either

so the sound created in runAbility doesn’t play? At a print at the very top of runAbility and see if it appears in the output. If it doesn’t then activateEvent seems to be the issue, but I don’t see any code relating to it on the client.

sorry for the late reply, I was sick, also if that’s the case, then why does it not work with activate event, and why does it affect studio differently, also I did make it work in studio because I had the wrong event name?

so you fixed your issue? char word count