[SOLVED] Function not running when OnClientEvent is called

So I’ve been working on effects in my game recently and when trying to run a function when OnClientEvent is fired.

What’s expected is when the event is fired it’s supposed to run a function that runs another function under certain conditions, that creates a Bezier Curve from the enemy’s humanoidRootPart to the player’s and tweens a part (acting like they’re stealing the soul or something).

This isn’t the case as when the event is actually fired, nothing happens. I’ve added debug prints to find out the issue but none of the prints actually execute. I’ve gone over the scripts using the event but nothing seems to be out of place.

Server (server module)

local function killSteal(plrChar, eChar, KillsVal)
	local VFXEvent = RPS.Events.GloveRemotes.KillstreakVFXEvent
	local SoulVFXEvent = RPS.Events.GloveRemotes.KillstreakSoulEvent -- THIS EVENT
	local PhaseEvent = RPS.Events.GloveRemotes.KSPhaseEvent
	local Event = RPS.Events.GloveRemotes.KSTextUpdEvent

	local player = Players:GetPlayerFromCharacter(plrChar)
	if not player then return false end

	local backpack = eChar:FindFirstChildOfClass("Backpack")
	local tool = eChar:FindFirstChild("Killstreak") or (backpack and backpack:FindFirstChild("Killstreak"))

	if tool and tool:FindFirstChild("Config") and tool.Config:FindFirstChild("KillsVal") then
		local enemyKills = tool.Config.KillsVal.Value
		local initialPlrKills = KillsVal.Value
		local killsStolen = math.floor(enemyKills / 2) + 1
		local Totalkills = player:FindFirstChild("leaderstats"):WaitForChild("Total Kills")
		local Monthlykills = player:FindFirstChild("leaderstats"):WaitForChild("Monthly Kills")

		if killsStolen > 0 then
			-- if own gamepass, receive kills in full
			if MPS:UserOwnsGamePassAsync(player.UserId, 911579621) then
				repeat
					KillsVal.Value += 1
					plrChar.Head.Overhead.Label.Text = KillsVal.Value
					VFXEvent:FireClient(player)
					PhaseEvent:Fire(plrChar, KillsVal.Value)
					Event:FireClient(player, KillsVal.Value)
					wait(0.05)
				until KillsVal.Value >= enemyKills
				return true
			end

			Totalkills.Value += 1
			Monthlykills.Value += 1
			SoulVFXEvent:FireClient(player, eChar:FindFirstChild("HumanoidRootPart")) -- Fire Event

Client (StarterPlayerScripts)

local PlayersService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local LocalPlayer = PlayersService.LocalPlayer

local Events = ReplicatedStorage:FindFirstChild("Events")
local GloveRemotes = Events.GloveRemotes
local RemoteEvent = GloveRemotes.KillstreakSoulEvent

local function handleEffect(character, enemyRootPart)
	print("received")
	local HRP = character:FindFirstChild("HumanoidRootPart")
	if not HRP then
		warn("effect failed: HumanoidRootPart missing from character")
		return
	end

	local soulTemplate = script:FindFirstChild("Soul")
	if not soulTemplate then
		warn("effect failed: soul template missing")
		return
	end

	if enemyRootPart then
		print("enemyRootPart found")

		local soul = soulTemplate:Clone()
		soul.Parent = workspace:FindFirstChild("Throwout") or workspace
		soul.CFrame = enemyRootPart.CFrame

		print("soul cloned at position:", soul.Position)

		local totalTime = 1.5
		local elapsedTime = 0
		local connection

		local function getQuadraticBezier(p0, p1, p2, t)
			return (1 - t)^2 * p0 + 2 * (1 - t) * t * p1 + t^2 * p2
		end

		connection = RunService.Heartbeat:Connect(function(dt)
			if not soul or not soul.Parent or not HRP or not HRP.Parent or not enemyRootPart or not enemyRootPart.Parent then
				if connection then connection:Disconnect() end
				if soul then soul:Destroy() end
				return
			end

			elapsedTime += dt
			local t = math.clamp(elapsedTime / totalTime, 0, 1)

			local START = enemyRootPart.Position
			local END = HRP.Position
			local MIDPOINT = (START + END) / 2 + Vector3.new(0, 8, 0)

			local newPos = getQuadraticBezier(START, MIDPOINT, END, t)
			soul.Position = newPos

			if t >= 1 then
				if connection then connection:Disconnect() end
				soul:Destroy()
				print("Task done")
			end
		end)
	else
		warn("Event fired without enemyRootPart")
	end
end


local function onEventFired(enemyRootPart)
	print("Received Event")

	local character = LocalPlayer.Character
	if not character then return end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	handleEffect(character, enemyRootPart)
	print("Called handleEffect")
end

RemoteEvent.OnClientEvent:Connect(onEventFired) -- RECEIVE EVENT

add a print before you send the remote to be sure it even sends in the first place, thats the only thing i can see causing this issue which means its the server script or its the localscript doing the dumb thing where it doesnt print errors

From what I can tell, SoulVFXEvent:FireClient(player, eChar:FindFirstChild("HumanoidRootPart")) is the line that is supposed to fire the remove event in your provided client script. If so, then I’d start by checking what the if statement conditions are evaluating as to determine whether or not the script even reaches the line. The conditions that seem to get in the way are not player, tool and tool:FindFirstChild("Config") and tool.Config:FindFirstChild("KillsVal"), and killsStolen > 0, so check those out first. This would also explain why your debug prints aren’t printing, granted that you’ve placed them within the scope of the if statements. After that, you might have to use your own discretion to figure out how to fix the problem.

TLDR, ensure that the if statements aren’t getting in the way.

Did so, nothing prints out as well. Like the script completely ignores anything related to the event

I managed to solve the problem which had something to do with the event variables. Thanks for the help guys!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.