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

why would this remote event script work? (a nil value)

Asked by
MHaven1 159
6 years ago
--local script--
script.Parent.MouseButton1Click:connect(function()
    game.ReplicatedStorage.Event:FireServer(script.Parent.Money, script.Parent.Price)
end)
--ServerScript--
game.ReplicatedStorage.Event.OnServerEvent:connect(function(player, money, price)
    if money.Value >= price.Value then
        print("Bought")
    else
        print("Not Bought")
    end
end)
--Error--
ServerScriptService.Script:2: attempt to index local 'money' (a nil value)

im using a remote event this is the error i get idk why it wont work everything is in its place nothing is missing but it still wont work.

0
line 2 your using a variable money which is nil or misspelled mattchew1010 396 — 6y
0
i just quickly remade that on this website nothing is misspelled or missing MHaven1 159 — 6y
0
it works when i add in the .Value in the local script MHaven1 159 — 6y
0
i dont want that because people will just exploit that easily MHaven1 159 — 6y
View all comments (2 more)
0
But there's no way to work unless you put .Value in the localscript. Time_URSS 146 — 6y
0
can i use a remote function? MHaven1 159 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago

Never trust the client! This script is completely flawed, as you said in the previous answer's comment "people can exploit it easily which is why i want to add in it .Value". This won't make any difference, anyone with RemoteSpy and basic lua knowledge can pass their own values through easily. I suggest you simply fire the server in the client with no parameters, then have their money and the price checked server side. I'm not sure why anyone would ever have their price client sided anyways because a exploiter can easily reduce it or make it negative and give their selves money. Anyways, I'm done rambling let me explain to you why its not working.

As the other person answered, you should add .Value to the end of the script, now before you comment the exact same thing you commented to him hear me out. I understand you are trying to make it so that its only passing the NumberValue, but in theory if I was an exploiter couldn't I just make my own NumberValues and pass it through?

I suggest you create a system where every player's money is stored into values in a folder in ServerStorage and then when it needs to be changed, the number in ServerStorage is changed and then a .Changed function fires the client to update whatever client sided things, like UI, need to be changed.

0
alrighty cool . TY MHaven1 159 — 6y
Ad
Log in to vote
2
Answered by
Lugical 425 Moderation Voter
6 years ago
Edited 6 years ago

Remember: The exploiter will always have the upper hand, so make sure to do as much as you can to stop them.

So coming from what you heard, you are going to have to send the server the value from the client anyway, as the server can't open it up. What I'd do is send the server the value, but to use some sort of sanity check. (I'll explain later)

Local:

script.Parent.MouseButton1Click:Connect(function() --Use :Connect instead.
    game.ReplicatedStorage.Event:FireServer(script.Parent.Money.Value, script.Parent.Price.Value) 

Server:

--Create another RemoteEvent, with a different name
local checked = false
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player, money, price)
checked = true
    game.ReplicatedStorage.Checking:FireClient(player, money, price) --This sends another message to the client.
   --Where's the other part? We'll get to it later.
    wait(2)
checked = false
end)

Other Local (Should be in the same local script as the other.

game.ReplicatedStorage.Checking.OnClientEvent:Connect(function(player, money, price)

    if money == script.Parent.Money.Value and price == script.Parent.Price.Value then
        game.ReplicatedStorage.Checking:FireServer(player, money, price)

end
end)

Other Server (Should be same script as the other server script part)

game.ReplicatedStorage.Checking.OnServerEvent:Connect(function(player, money, price)
if checked == true then
 if money >= price then
        print("Bought")
    else
        print("Not Bought")
    end
end
checked = false
end)

So what did we do? To some, this is called a sanity check. These are used to try to make an exploiter's achievement harder. Note that exploiters will always have the upper hand, but can be dealt with. (They can read and alter client code, but with the right set-up, we can get back at 'em.)

In our first part of the local script, we just sent the values. However, they'll be check later on. In the first part of the server script, it actually sends the information right back to the client with a different RemoteEvent, and this is where we're able to compare information. We also set up a variable that's set to true when the RemoteEvent is passed to the server (Remember, exploiters can't edit server code!) On the last part of the local script, it compares the numbers the server has and the numbers you currently have. If they match, huzzah, they'll go up to the server again. If it doesn't, it'll reject it and stop the pro if money >= price then print("Bought") else print("Not Bought") end process. And then on the last part of the server, it'll see if that checked value is right, making sure a hacker didn't send an event up from the client directly. After that, it'll then mark your purchase. Hopefully this isn't too confusing, and if you have any questions, I'll be glad to help.

0
TY bro this helped alot. MHaven1 159 — 6y
Log in to vote
0
Answered by
Time_URSS 146
6 years ago

I think the problem could be when you're sending a value through the RemoteEvent, instead of:

game.ReplicatedStorage.Event:FireServer(script.Parent.Money, script.Parent.Price)

try to put

game.ReplicatedStorage.Event:FireServer(script.Parent.Money.Value, script.Parent.Price.Value)

If it doesn't work, then I don't know how to solve it.

Hope it works!

0
that works but people can exploit it easily which is why i want to add in it .Value in the server side MHaven1 159 — 6y

Answer this question