OnClientEvent or OnServerEvent in a localscript?

well my problem is that the following localscript, it should detect the FireServer of another local script, but it doesn’t. It does not give error in the output nor does it give the print, so I do not know if it is OnClientEvent or OnServer event, I already tried both but it does not work

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ScreenBarBgGraphicsFire = ReplicatedStorage:WaitForChild("ScreenBarBgGraphicsFire")


local loadingScreen = script.Pantallacarga
loadingScreen.Parent = game.Players.LocalPlayer.PlayerGui

local function FireBarBg(Position, Text)
loadingScreen.Background.BarBG.Bar:TweenSize(UDim2.new(Position), nil, nil, 0)
loadingScreen.Background.Counter.Text = Text
print("siu")
end

ScreenBarBgGraphicsFire.OnServerEvent:Connect(FireBarBg)
2 Likes

is this script in a client script? If so change OnServerEvent to OnClientEvent, and when doing OnServerEvent you would always have to put: OnServerEvent:Connect(player --Always put this, --Your value here)

local function FireBarBg(player, Position, Text) something like that? it doesn’t work

1 Like

I think you need to fire the client in the server in order for it to run OnClientEvent.

1 Like

If you’re handling this on the client:

Use OnClientEvent/FireServer(), using OnClientEvent doesn’t require the Player parameter and will receive the requests when FireClient() is called on the server, while OnClientEvent() is waiting to receive that said “request” (Client-wise)

If you’re handling this on the server:

Use OnServerEvent/FireClient(), using OnServerEvent will receive the requests when FireServer() is called on the client, which gives the Player Instance the first parameter, while FireClient() requires that said “Player Instance”

It depends on your use case here

(translate this)
no se bien lo que querias hacer pero el primer error es que un localScript no puede detectar el FireServer de otro localScript sin un intermediario

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ScreenBarBgGraphicsFire = ReplicatedStorage:WaitForChild("ScreenBarBgGraphicsFire")


local loadingScreen = script.Pantallacarga
loadingScreen.Parent = game.Players.LocalPlayer.PlayerGui

local function FireBarBg(plr, Position, Text) --changed
if tostring(plr.Name) == tostring(game.Players.LocalPlayer.Name) then
loadingScreen.Background.BarBG.Bar:TweenSize(UDim2.new(Position), nil, nil, 0)
loadingScreen.Background.Counter.Text = Text
print("siu")
end
end

ScreenBarBgGraphicsFire.OnClientEvent:Connect(FireBarBg) --changed

tendras que añadir un script (no local y en ServerScriptService) y poner el siguente codigo

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ScreenBarBgGraphicsFire = ReplicatedStorage:WaitForChild("ScreenBarBgGraphicsFire")
ScreenBarBgGraphicsFire.OnServerEvent:Connect(function(goFor,arg1,arg2) --plr, Position, text
ScreenBarBgGraphicsFire:FireAllClients(goFor,arg1,arg2)
end)
1 Like

Maybe if you read the wiki you can find out.

ah, gracias. realmente no sabía que hacer con esto y se me acababan las soluciones

1 Like

hablo español tambien jajaja, te lo agradezco

1 Like

jsjasksjs yo tambien
saludos desde argentina capo

1 Like