[Solved] Get player on server side?

  1. What do you want to achieve?

My brain is melting, for an idea. I have some ducks in workspace and every 3 seconds i want the ducks to send a remoteEvent to the server to store in the dataStore

  1. What is the issue?

I geniuly can’t , i did a while wait loop in a PlayerAdded function but it dosent work. Please help

  1. What solutions have you tried so far?

None of the solutions i found seem to help

First server side

local repStorage = game:GetService("ReplicatedStorage")
local Events = repStorage:FindFirstChild("Events")
local AddPoint = Events:FindFirstChild("AddPoint")

game.Players.PlayerAdded:Connect(function(player)
	while wait(3) do
		AddPoint:FireClient(player,1)
	end
end)

Client:


local repStorage = game:GetService("ReplicatedStorage")
local Events = repStorage:FindFirstChild("Events")
local AddPoint = Events:FindFirstChild("AddPoint")

AddPoint.OnClientEvent:Connect(function(player,point)
	print(point)
	AddPoint:FireServer(point)
end)
1 Like

I’m not understanding this 100%, does the point not add? Do you get an error of some sort?

1 Like

The point is that i cant fire the client to the server

Can I see the script for the client to server event?

1 Like

can’t you just use a bindable event?

1 Like

You dont seem like you understand. I just can’t seem to find a way to get the player to fire the client event

How would that work? Never used that

If all you’re doing is Firing the “AddPoint” event in that script you can loop through all the children in players and fire it (and then put it in a true loop)

while true do
    for _, Player in pairs(game.Players:GetChildren())
        AddPoint:FireClient(Player, 1)
    end
end

Although @x_Kranxy the use of the code here is really confusing and doesn’t really make sense. Could you explain this in a bit more detail please? Maybe I could help you a bit more.

a bindable event is like a remote event apart from instead of going from client to server or server to client you can do client to client or server to server

local repStorage = game:GetService("ReplicatedStorage")
local Events = repStorage:FindFirstChild("Events")
local AddPoint = Events:FindFirstChild("AddPoint")

game.Players.PlayerAdded:Connect(function(player)
	while wait(3) do
		AddPoint:FireClient(player,1)
	end
end)

AddPoint.OnServerEvent:Connect(function()
	warn(" ¬¬ ")
	warn("save dss :p ")
end)

So, i have a duck mesh in workspace. Any many other spawing along,i want them so every 3 seconds they give a point. (the point is given in the dataStore script via a remoteEvent) thats what its suppose to do atleast

OnClientEvent doesn’t have the player as the first argument. That’s only for OnServerEvent.

As stated by @weding3 use a BindableEvent.

Something like this should work:

local BindableEvent = game:GetService("ReplicatedStorage").Event

game.Players.PlayerAdded:Connect(function(Player)
	while true do
		BindableEvent:Fire(Player, 1)
		task.wait(3)
	end
end)

BindableEvent.Event:Connect(function(Player, Amount)
	Player.leaderstats.Points.Value += Amount
end)

If you are still unsure on BindableEvents click here

My bad, thanks for the tip tho.

Consideing you added player as an argument on OnClientEvent, It is being treated as the point and not point itself meaning this will happen

AddPoint.OnClientEvent:Connect(function(player,point)
	print(point) -- This prints player!
	AddPoint:FireServer(point) -- This fires as player argument!
end)
--Fix
AddPoint.OnClientEvent:Connect(function(point)
	print(point) 
	AddPoint:FireServer(point)
end)

So why are u sending it to the client for data saving anyway?

Yea so you see. That dosent work. It could be the same with a RemoteEvent but if you try to do a loop inside a PlayersAdded function dosent work

It works fine for me, I’m unsure what the issue is.

Beacuse i cant send it from a Server function to another Server funciton via RemoteEvents

That is what bindable events do :smiley:

1 Like