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
What is the issue?
I geniuly can’t , i did a while wait loop in a PlayerAdded function but it dosent work. Please help
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)
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
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
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)