LocalScript FireServer() not working, or OnServerEvent not working

The topic says it all. I’m sure that this should work but no. No errors also. Already browsed the forum and went to Googles page 2(I’m desperate).
Here’s my localscript located in players PlayerGui, i created 2 for replicating, both are printing but neither is firing:
LocalScript1:

local RS = game:GetService("ReplicatedStorage")
local RequesteffectEvent = RS:WaitForChild("Requests"):WaitForChild("RequestEffect"):WaitForChild("ProcessRequest")
local container = script.Parent

-- Function to handle button clicks
local function onButtonClick(itemButton)
	print("Button clicked:", itemButton.Name) -- 'this' refers to the button that was clicked
	-- Add your custom logic here
	RequesteffectEvent:FireServer()
end

-- Iterate through existing descendants to find and set up buttons
for _, itemButton in pairs(container:GetDescendants()) do
	if itemButton:IsA("TextButton") then
		itemButton.MouseButton1Click:Connect(function()
			onButtonClick(itemButton)
		end)
	end
end

container.ChildAdded:Connect(function(itemButton)
	if itemButton:IsA("TextButton") then
		itemButton.MouseButton1Click:Connect(function()
			onButtonClick(itemButton)
		end)
	end
end)

LocalScript2:

local RequestBtn = script.Parent
local RS = game:GetService("ReplicatedStorage")
local RequesteffectEvent = RS:WaitForChild("Requests"):WaitForChild("RequestEffect"):WaitForChild("ProcessRequest")
RequestBtn.MouseButton1Click:Connect(function()
	print("Requesting Effect")
	RequesteffectEvent:FireServer()
end)

ServerScript:

local RS = game:GetService("ReplicatedStorage")
local RequesteffectEvent = RS:WaitForChild("Requests"):WaitForChild("RequestEffect"):WaitForChild("ProcessRequest")
local EffectsFolder = RS:WaitForChild("Effects")
RequesteffectEvent.OnServerEvent:Connect(function(player)
	print(player.Name)
end)

Code seems valid. Seems like your issue could be that the OnServerEvent event is never connected to the function; i.e. the code in the first 3 lines (the effectsfolder one) of your server script is stalling the script to the point that the event can never actually be ran. You can test this by putting a print at the bottom of your server script and checking if it prints or not. If that is the case, then double check your explorer and your :WaitForChild statements, make sure the things they’re waiting for are actually there

1 Like

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