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

I am wanting to give money to a player through this script, How could I do this?

Asked by 6 years ago

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?

1local plrm = game.ServerStorage.PlayerMoney
2local plr = game.Players.LocalPlayer
3 
4script.Parent.MouseButton1Down:Connect(function()
5    plrm.plr.Value = plrm.plr.Value + 100000
6end)

Thank you - eizaray1234

0
It's a local script if that helps. eizaray1234 -12 — 6y
0
The contents of ServerStorage are not replicated to clients at all; move the "PlayerMoney" to ReplicatedStorage or use a RemoteEvent. User#19524 175 — 6y
0
On row 4 you've written; game.ServerStorage.PlayerMoney.game.Players.LocalPlayer Spjureeedd 385 — 6y

2 answers

Log in to vote
0
Answered by
Hizar7 102
6 years ago

the RemoteEvent as the above comment has mention would be added into your script as seen below

LOCAL SCRIPT

1local plrm = game.ServerStorage.PlayerMoney
2local plr = game.Players.LocalPlayer
3script.Parent.MouseButton1Down:Connect(function()
4game.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

1local myName = "PlayerMoney"
2game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
3local  plrm = game.ServerStorage:FindFirstChild(myName)
4 plrm.plr.Value = plrm.plr.Value + 100000
5end)

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!

0
On line 5 of the Server Script it says "plr is not a valid member of Folder" eizaray1234 -12 — 6y
Ad
Log in to vote
1
Answered by
crywink 419 Moderation Voter
6 years ago
Edited 6 years ago

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

1local event = game.ReplicatedStorage.RemoteEvent
2 
3script.Parent.MouseButton1Down:Connect (function()
4    event:FireServer(100000)
5end)

Server Script (put this in ServerScriptService)

1local event = game.ReplicatedStorage.RemoteEvent
2local plrm = game.ServerStorage.PlayerMoney
3 
4event.OnServerEvent:Connect (function(plr, amount)
5    plrm[plr.Name].Value = plrm[plr.Name].Value + amount
6end)

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.

0
The remote event isn't secure. A client can send math.huge or something and it could work User#19524 175 — 6y
0
That’s correct, but I’ve never used this tycoon kit before and I don’t know how he wants to throttle who can and cannot fire the event. crywink 419 — 6y

Answer this question