OnClientEvent won't receive message from FireAllClients()

  1. What do you want to achieve? Keep it simple and clear!

I want a text gui to show the same text for all players in a server

  1. What is the issue? Include screenshots / videos if possible!

–script–
game.ReplicatedStorage[“Money transfer”]:FireAllClients()

–local script–
game.ReplicatedStorage[“Money transfer”].OnClientEvent:Connect(function()

money += 1
print(“Message received”)

end)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried searching through the DevForum and on other websites.

1 Like

That’s how it’s done. The problem is elsewhere, such as where the scripts are, what types of scripts they are, whether the code has any errors, etc. Confirm that both scripts are actually running first.

Sorry this was my first post, but both scripts are running and there are no errors.

you might want to delay the server script by 3 seconds
( it might be firing before the client connects to the server )

I just tried putting a wait(3) in my script but it still didn’t work.

here is my entire script

—Varibles—

local money = 0

local debounce = 1

—Code—

game.Workspace.Model.Gerold.ClickDetector.MouseClick:Connect(function()
if debounce == 1 then
debounce = 2
wait(0.2)
local money = game.ServerStorage.Money:Clone()
money.CFrame = game.Workspace.Model.Part.CFrame
money.Parent = workspace
debounce = 1
end
end)

while true do
wait()
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == “Money” then
v.Touched:Connect(function(object)
if object.parent:FindFirstChildWhichIsA(“Humanoid”) then
v:Destroy()
money += 1
game.Workspace.Moneynumber.Value += 1
game.ReplicatedStorage[“Money transfer”]:FireAllClients()
else
wait(5)
v:Destroy()
end
end)
end
end
end

Oh okay. does the client code have to wait a long time to get the event triggered? maybe move the remote connection somewhere to connect faster.

I tried this but the client still dose not print

local function fireclient()

game.ReplicatedStorage[“Money transfer”]:FireAllClients()

print(“fired”)

end

fireclient()

oh this is a client script? you need a [“Money transfer”].OnClientEvent:Connect(function())

That script works but the local script won’t print

here is my entire local script

—Varibles—

local money = 0

local shopframe = game.Workspace.House.Shop.SurfaceGui.Frame

local Newpositon = game.Workspace.House.Newshop.CFrame

local oldposition = CFrame.new(-17.6289692, 4.67552853, 20.9015789, 1, -0, 0, 0, 0.984812498, 0.173621148, -0, -0.173621148, 0.984812498)

local Tweenservice = game:GetService(“TweenService”)

local shop = game.Workspace.House.Shop

local partTween = Tweenservice:Create(shop, TweenInfo.new(2, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 0, false, 0), { Size = Vector3.new(7, 4, 0.3), CFrame = Newpositon})

local partTweenreverse = Tweenservice:Create(shop, TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0), { Size = Vector3.new(3, 1.6, 0.3), CFrame = oldposition})

—Code—

for i, v in pairs(game.Workspace.House.Laptop:GetChildren()) do
local clickdetecter = Instance.new(“ClickDetector”)
clickdetecter.Parent = v
v.ClickDetector.MouseClick:Connect(function()
partTween:Play()
shopframe.Visible = true
end)
end

game.Workspace.House.Shop.SurfaceGui.Frame.Close.MouseButton1Click:Connect(function()
partTweenreverse:Play()
wait(0.2)
shop.SurfaceGui.Frame.Visible = false
end)

while true do
wait()
script.Parent.ScreenGui[“Money gui”].Text = "$: "…money
end

game.ReplicatedStorage[“Money transfer”].OnClientEvent:Connect(function()
money += 1
print(“Message received”)
end)

I know its a little weird but just for a test move the onclient event right underneath money and test the code

that should tell you if the code is getting connected after the event is fired to the client

1 Like

I moved this function around and for some weird reason it works at the top of my local script. Thanks for the help :grinning: :+1:

game.ReplicatedStorage[“Money transfer”].OnClientEvent:Connect(function()
money += 1
print(“Message received”)
end)

Yep no problem!

I think you were doing too many things before connecting the function to the remote ( it waits to long )
and the server already tried telling it to do MoneyTransfer, but the client didnt know it was supposed to do that until later.

1 Like