This bug has been driving me absolutely crazy for the past two days. I'm trying to dabble in scripting/developing again for like the millionth time and this time I am NOT letting a bug like this frustrate me into abandoning the game entirely.
Basically, I'm trying to incorporate FE and remotes into old value-changing scripts that didn't have them. The first script goes as such and isn't problematic, it's in Workspace:
local Players = game:GetService("Players") local SSS = game:GetService("ServerScriptService") -- This line has been replaced many times local CPE1 = Instance.new("RemoteEvent") CPE1.Parent = SSS.CPE1SS -- This one too CPE1.Name = "CPE1Event" local function onCP(player) CPE1:FireClient(player) end Players.PlayerAdded:Connect(onCP)
The second script is problematic...I've tried everything with it, I've had it in Workspace, as a regular script in ReplicatedFirst, a LocalScript in ReplicatedFirst, a Local in ReplicatedStorage, a Script in ServerScriptService...but I'm beginning to think something else is up because the script doesn't successfully run anywhere.
print("Working") local Event = script:WaitForChild("CPE1Event") print("Working actually") local function MonthlyReportFunction() print("Function works") while true do print("Loop is working") game.Players.LocalPlayer.LastMonthMoneyMade.Value = game.Players.LocalPlayer.MonthlyReportMoneyMade.Value wait(3) end end
'Working' and 'Working actually' print, but 'Function works' doesn't and nothing after that does. Why is my game refusing to run this function??
I'm guessing this is because I lack understanding of remotes and they work...?
In any case, thanks for reading this and potentially trying to help me
I assume you're trying to run the second script when you fire the RemoteEvent.
Your second script will need to be run on the client, so it must be a LocalScript. Additionally, it needs to be placed somewhere on the client, I recommend StarterPlayerScripts
. Also, your RemoteEvent needs to be placed somewhere where both the client and server can access it, like ReplicatedStorage
(And not ServerScriptService)
Lastly, you need to connect the function to an event so that it fires. The event you'll use is OnClientEvent
as that will fire when FireClient
is called from the other script.
After placing the LocalScript properly, simply add this line to the end of it:
RemoteEvent.OnClientEvent:Connect(MonthlyReportFunction)
(Where RemoteEvent is replaced by the correct path to your RemoteEvent, preferably in ReplicatedStorage.
EDIT: While this should fix your issue, really you don't need the LocalScript at all. Everything you do in that script can be done on the server, and it can be done safely. When working with FilteringEnabled, the general rule is to never trust the client. Exploiters can alter anything that's on their client, so if you trust the values coming from the client you could be allowing exploiters to take advantage of your game. Exploiters cannot, however, alter things directly on the server (Unless you let them by trusting their values coming from RemoteEvents) so any important calculations and changes should be made on the server.