Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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)
0
Thanks :D i'll test it out. Hugo_XPGamer 8 — 5y
0
friend me NYDynamics 71 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)
0
So would i put the normal script in serverscriptservice? Hugo_XPGamer 8 — 5y
0
Yes! heinekaN 0 — 5y
Log in to vote
0
Answered by 5 years ago

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.

Answer this question