I am having a problem about a Remote Event, any help is really appreciated!!.
My issue is that, the object “event” doesn’t fire unless the function “Spectral_Shield” Is called, like for example, if I triggered Soul mend function without the spectral function running not even once, the event doesn’t fire. When the Spectral Shield is called, the event will work fine afterwards. However I want it so that it doesn’t have to require that function to run first before the events to work normally. I have setted up no such condition to wait for the function spectral shield to be called, I only fire the event Normally like if a player presses a certain key, it will activate. And i have not setted up a condition such that the Spectral Shield is needed first. I have tried many ways including using different remote events for a specific function but It didn’t work. I have run out of ideas and may need some Help or understandment.
The script is in serverscriptservice, the local script is from the starterplayerscript to receive the signal.
This is the script I have:
local skillModule = require(script.Parent)
local skills = script.Skills
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local SSS = game:GetService("ServerScriptService")
--Events
local event = RS:WaitForChild("Events"):WaitForChild("skill_Handler"):WaitForChild("EVENT")
local Bind = SSS.skillHandler.Bind
local function Soul_Mend(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
local cache = char:FindFirstChild("Cache")
local skillName = skills:FindFirstChild("Soul_Mend")
--Objects
local IncreaseInCircle = math.random(5, 12)
local delayHealthIncrease = math.random(1.3, 1.99)
local cooldown = 5
event:FireClient(plr)
print("HEY!")
for i = 1, 4, 1 do
task.wait(delayHealthIncrease)
hum.Health += IncreaseInCircle
end
end
local function Spectral_Shield(plr)
local plrgui = plr.PlayerGui
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
local cache = char:FindFirstChild("Cache")
local shield
local skillName = skills:FindFirstChild("Spectral_Shield")
local shieldSystemModule = require(skillName:FindFirstChild("ShieldSystem"))
if not cache:FindFirstChild("ssShield") then
shield = Instance.new("BoolValue")
shield.Parent = cache
shield.Name = "ssShield"
event:FireClient(plr)
local shieldFormation = shieldSystemModule.new(plr, 100, 0, 0)
elseif cache:FindFirstChild("ssShield") then
cache:FindFirstChild("ssShield"):Destroy()
end
end
Bind.Event:Connect(function(plr, skillName)
print("Firedddd")
if skillName == "Spectral_Shield" then
Spectral_Shield(plr)
elseif skillName == "Soul_Mend" then
Soul_Mend(plr)
end
end)
-- Client Script
local event = RS:WaitForChild("Events"):WaitForChild("skill_Handler"):WaitForChild("EVENT")
event.OnClientEvent:Connect(function()
print("IDK MAN")
end)
I have run out of ideas to fix this. Any help or idea or maybe an info is appreciated!
1 Like
Can you post the section of code that fires the SSS.skillHandler.Bind
BindableEvent? That seems like relevant information here, since it’s what’s kicking off the event on the server
Also one note, event.FireClient(plr)
should be event:FireClient(plr)
– note the : instead of .
Please post anything from the Output
tab that could be indicating that there are other problems in your script.
You should have errors showing up. You are calling the FireClient function with .
instead of :
.
--Server
local eventFromClient = RS:FindFirstChild("EVENTCLIENT")
local function skillActivationHandler(plr, key)
local keybindFolder = plr.Keybind
for _, keys in pairs(keybindFolder:GetChildren()) do
if keys.Name == key then
if keys.Value ~= "" then
if availSkills:FindFirstChild(keys.Value) then
print("Activating : ".. keys.Value)
BindEvent:Fire(plr, keys.Value)
break
end
end
else
print("keys not found.")
end
end
end
eventFromClient.OnServerEvent:Connect(skillActivationHandler)
--Client
local uis = game:GetService("UserInputService")
local eventFromClient = RS:WaitForChild("EVENTCLIENT")
uis.InputBegan:Connect(function(input)
for i, key in pairs(skillKey) do
if input.KeyCode == Enum.KeyCode[key] then
eventFromClient:FireServer(key)
end
end
end)
Sorry it took long
I’m pretty sure I didn’t, I wonder why iit’s event.FireClient there but it’s not in my script, i thought that was a mistake, I was almost happy 
You might try adding print statements or a debugger breakpoint in your skillActivationHandler
function between each line to make sure that it’s getting through those conditions as expected.
Sadly, I have tried printing every single thing related to activating the script, however they work fine in the client, just the event for me is the issue 
Is there any other ways to communicate to the client? any methods will be welcomed please
Can you use this function with these print statements, try pressing the keys you expect, and then share the output here?
local function skillActivationHandler(plr, key)
print(`\nPlayer: {plr.Name} is trying to activate skill: {key}`)
local keybindFolder = plr.Keybind
for _, keys in pairs(keybindFolder:GetChildren()) do
if keys.Name == key then
print(`Key {key} found.`)
if keys.Value ~= "" then
print(`Keys value {keys.Value} is not empty.`)
if availSkills:FindFirstChild(keys.Value) then
print(`Skill {keys.Value} found in availSkills. Activating {keys.Value}`)
BindEvent:Fire(plr, keys.Value)
return
end
warn(`WARNING: keys.Value} is not found in availSkills.`)
end
warn(`WARNING: Keys value {keys.Value} is not empty.`)
end
end
warn("WARNING: Key not found in keybindFolder.")
end
I’m asking because this is the first response to the event, so we need to verify that this works before checking the rest of the code.
This is the issue, if I use soul mend function, it doesn’t fire, and also I’ve used the script you provided.
I’ve shown the video that if I fire the Spectral function, the event worked fine and then afterwards the soul mend function can run perfectly normal as well. (When the IDK MAN prints, it means the event finally fired)
PS:I may have to leave so I apologize in advance, I will reply to your message later. I really thank you for helping me 
The fact that HEY!
is printing indicates that your Soul_Mend function actually is running just fine, but your client is not connected to the EVENT
at that time.
Then, when you equip a skill, it finally connects the client to EVENT
and it processes the queued up events (thus IDK MAN
prints 7 times as soon as the skill is equipped)
So you need to figure out why your client script isn’t connecting to EVENT
right away until a new skill is equipped.
It’s not when I equip a skill, It’s that if i equip other than Spectral function, the EVENT will not fire unless the “Spectral” function was fired. After the spectral function is fired, the event will also fire as well and the event will work normally as I intended it to do. Although no such conditions was set up, it seems to work that way.
That’s my problem and the whole issue of this point, why can’t this event connect to the client right away when the scripts provided looks fine?
Do you see print at the first video I sent to you, I equipped Soul_Mend, yet the event does not fire, however when I equipped Spectral function, it fires perfectly, then afterwards I presented you that the event works properly after the event fire.
I tried considering to fire the spectral function after the player joins, it doesn’t work too.
Someone please assist for those who have any idea how to fix this, any help will be very much appreciated!
Please show RS/Events/skillHandler/Event code
Sorry if I was unclear or if I’m misunderstanding, but here’s what I meant to say in a more clear breakdown of what I think is happening:
- The server does fire the event when expected
- But the client is not connected to the event
- So the event gets added to a queue, waiting for the client to connect
- Once the client connects, it processes the whole queue e.g. receives all the events that were backed up waiting for the connection
- Events fired after this show up right away on the client since it’s already connected
So I suspect something is not set up correctly where you connect from the client.
- Do you have one or multiple client scripts listening for the event?
- Where is the script(s) located?