I'm wanting to this script to give 100,000 dollars if a player clicks the GUI, I'm using Zed's Tycoon Kit, and I was wanting to make a Mod Menu sort of script, Why won't this give money to a player?
1 | local plrm = game.ServerStorage.PlayerMoney |
2 | local plr = game.Players.LocalPlayer |
3 |
4 | script.Parent.MouseButton 1 Down:Connect( function () |
5 | plrm.plr.Value = plrm.plr.Value + 100000 |
6 | end ) |
Thank you - eizaray1234
the RemoteEvent as the above comment has mention would be added into your script as seen below
LOCAL SCRIPT
1 | local plrm = game.ServerStorage.PlayerMoney |
2 | local plr = game.Players.LocalPlayer |
3 | script.Parent.MouseButton 1 Down:Connect( function () |
4 | game.ReplicatedStorage.RemoteEvent:FireServer() -- added the RemoteEvent to the local script |
5 | plrm.plr.Value = plrm.plr.Value + 100000 |
6 | end ) |
then you'd make your server script with the opposite end of the RemoteEvent that will fire when thisRemoteEvent is activated
SERVER SCRIPT
1 | local myName = "PlayerMoney" |
2 | game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect( function (plr) |
3 | local plrm = game.ServerStorage:FindFirstChild(myName) |
4 | plrm.plr.Value = plrm.plr.Value + 100000 |
5 | end ) |
Dont forget to add the RemoteEvent to the replicatedStorage. If you rename the RemoteEvent something else make sure that you name in the in both your scripts.
Personally i've never grabbed a value out of serverstorage this way but it should work none the less, let me know, Thanks!
Hey there!
I’ve never used this tycoon kit before but I would assume your issue is that your changes aren’t replicating to the server and that the client can not access ServerStorage. To fix this, you would use a Remote Event or Remote Function.
Here’s how you would do it...
Local Script
1 | local event = game.ReplicatedStorage.RemoteEvent |
2 |
3 | script.Parent.MouseButton 1 Down:Connect ( function () |
4 | event:FireServer( 100000 ) |
5 | end ) |
Server Script (put this in ServerScriptService)
1 | local event = game.ReplicatedStorage.RemoteEvent |
2 | local plrm = game.ServerStorage.PlayerMoney |
3 |
4 | event.OnServerEvent:Connect ( function (plr, amount) |
5 | plrm [ plr.Name ] .Value = plrm [ plr.Name ] .Value + amount |
6 | end ) |
Note: you’ll need to insert a RemoteEvent into ReplicatedStorage
If this didn’t help, feel free to comment with any questions regarding your issue.
If this helped, please accept and upvote this answer.