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 5 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?

local plrm = game.ServerStorage.PlayerMoney
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Down:Connect(function()
    plrm.plr.Value = plrm.plr.Value + 100000
end)

Thank you - eizaray1234

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

2 answers

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

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

LOCAL SCRIPT

local plrm = game.ServerStorage.PlayerMoney
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer() -- added the RemoteEvent to the local script
 plrm.plr.Value = plrm.plr.Value + 100000
    end)

then you'd make your server script with the opposite end of the RemoteEvent that will fire when thisRemoteEvent is activated

SERVER SCRIPT

local myName = "PlayerMoney"
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
local  plrm = game.ServerStorage:FindFirstChild(myName)
 plrm.plr.Value = plrm.plr.Value + 100000
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!

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

local event = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Down:Connect (function()
    event:FireServer(100000)
end)

Server Script (put this in ServerScriptService)

local event = game.ReplicatedStorage.RemoteEvent
local plrm = game.ServerStorage.PlayerMoney

event.OnServerEvent:Connect (function(plr, amount)
    plrm[plr.Name].Value = plrm[plr.Name].Value + amount
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.

0
The remote event isn't secure. A client can send math.huge or something and it could work User#19524 175 — 5y
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 — 5y

Answer this question