Somebody, please make this make sense- It chooses when it wants to work. i can load studio for 4 - 5 seconds it uses the remote and the server picks it up. The client will always trigger the remote but the server doesn’t always get it, aleast thats what im getting from my prints.
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
print("Go")
game.ReplicatedStorage.ClapEvent:FireServer(tick())
RunClap()
end
end)
SERVER CODE BELOW
local Players = game.Players
Players.PlayerAdded:Connect(function()
for _,Player in pairs(Players:GetChildren()) do
local MyData = require(game.ReplicatedStorage.Modules.MyData); MyData.SetPlayer(Player)
local Clapspeed = MyData.Get_MyFolder():WaitForChild('Clapspeed')
local Cash = MyData.Get_MyFolder():WaitForChild('Cash')
local LastClap = 0
local Char = Player.CharacterAdded:Wait()
local Remote = game.ReplicatedStorage:WaitForChild("ClapEvent")
Remote.OnServerEvent:Connect(function(plr, Time)
if Time - Clapspeed.Value <= LastClap or LastClap == 0 then
print("CurrentTime -"..Time)
print("LastTime -"..LastClap)
Cash.Value = Cash.Value + 1
LastClap = Time
print("LastTimeUpade -"..LastClap)
end
end)
end
end)
It isn’t viable to be listening to an event within a PlayerAdded event. This makes unnecessary connections which can be dangerous for memory, causing lag.
Why are you looping through Players when PlayerAdded is ran? This means a new MyData object will be created for every player, every time a new player is added.
All your variables are accessible outside of the PlayerAdded event, you are passing plr, the client who fired the remote. You should use that argument to create a MyData object & create other variables instead.
Listen to the remote outside of the PlayerAdded event.
The following code can be used to achieve the tasks at hand.
Remote.OnServerEvent:Connect(function(plr, Time)
local MyData = require(game.ReplicatedStorage.Modules.MyData); MyData.SetPlayer(plr)
local Clapspeed = MyData.Get_MyFolder():WaitForChild('Clapspeed')
local Cash = MyData.Get_MyFolder():WaitForChild('Cash')
local LastClap = 0
local Char = plr.CharacterAdded:Wait()
local Remote = game.ReplicatedStorage:WaitForChild("ClapEvent")
if Time - Clapspeed.Value <= LastClap or LastClap == 0 then
print("CurrentTime -"..Time)
print("LastTime -"..LastClap)
Cash.Value = Cash.Value + 1
LastClap = Time
print("LastTimeUpade -"..LastClap)
end
end)