Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

0

It's a local script if that helps.

0

The contents of ServerStorage are not replicated to clients at all; move the "PlayerMoney" to ReplicatedStorage or use a RemoteEvent.

0

On row 4 you've written; game.ServerStorage.PlayerMoney.game.Players.LocalPlayer

2 answers

✓ Accepted answer

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!

1 comment

0

On line 5 of the Server Script it says "plr is not a valid member of Folder"

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.

2 comments

0

The remote event isn't secure. A client can send math.huge or something and it could work

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.