Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i fix my FE compatible script so it works in game?

Hello, i have been learning a lot about Filtering Enabled lately but i still do not get it. I started writing this script but it only works in Roblox Studio. Can someone please help me?

Inside a textbutton in a local script

RS = game.ReplicatedStorage.CollectCashEvent

script.Parent.MouseButton1Click:Connect(function()
RS:FireServer(50)
end)

Inside the textbutton in a normal script

user = game.Players.LocalPlayer
RS = game.ReplicatedStorage.CollectCashEvent

RS.OnServerEvent:Connect(function()
user.leaderstats.Cash.Value = user.leaderstats.Cash.Value + number
end)

3 answers

game.Players.LocalPlayer --cant be used in a server script aka normal only local scripts

You cant use game.Players.LocalPlayer in a script but u can use it in a local script

So.. change the script in the textlabel to a regular script make the one that runs it a local and instead of OnServerEvent or FireServer so

	--Regular Script
	Event:FireServer()
	--and then 
	--local script
	Event.OnClientEvent:connect(function()
		--Code when ran
	end)

2 comments

0

Thanks :D i'll test it out.

0

friend me

You should probably let the server determine the amount of Cash that the player is given.

Server script:

RS = game.ReplicatedStorage.CollectCashEvent

number = 50

-- Make sure Player is in the function arguments so we know what player to give it to
RS.OnServerEvent:Connect(function(Player)
	Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + number
end)

Local script:

RS = game.ReplicatedStorage.CollectCashEvent
 
script.Parent.MouseButton1Click:Connect(function()
	RS:FireServer()
end)

2 comments

0

So would i put the normal script in serverscriptservice?

0

Yes!

The problem with your event is that instead of using the Client argument that is returned automatically with the server event, you're trying to use Players.LocalPlayer, which can't be accessed from a server script.

Instead what you should be doing is:

RS = game.ReplicatedStorage.CollectCashEvent
	 
RS.OnServerEvent:Connect(function(client)
	client.leaderstats.Cash.Value = client.leaderstats.Cash.Value + number
end)

The RemoteEvent automatically returns the Player that fired it as the first argument.

This discussion is preserved as it was. New answers, comments, and votes are closed.