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

Can anyone please help me making a tool that gives me money every time I click?

Asked by 5 years ago

So I've been trying to make a simulator game and been having trouble getting the money to change every time you click when the item that gives you money is equipped. (If anyone could help me to get users 5 XP every 10 clicks with levels that would be amazing too!)

Here is my code (LocalScript inside of the tool)

local tool = script.Parent
local cash = game.Players.LocalPlayer.leaderstats.Money.Value

function onActivation()
    cash.Value = cash.Value + 1
end

tool.Activated:Connect(onActivation)

Sadly, the script doesn't work! Could someone please help me on my project?

I am also trying to make a shop and I'm very clueless on how to make it. If someone could put in the script and provide details for all the code used in it I would highly appreciate it!

Thank you. -Aidan

0
This is a borderline request, so im not gonna type it out. But the issue you're having is FE, you need to use a remote event to change the cash value. This is a very common issue and should be easy to find the answer with the search feature. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The issue at hand


The issue here is that you are trying to change values that do not permit the client to them them, on the client. This Client , Server separation is what is known as Filtering Enabled and is forced upon all roblox games. It exists as a security measure to prevent exploiters and "hackers"

Filtering Enabled


Filtering Enabled, or Network Filtering, or FE prevents the client or player from accessing items in Server Storage and Server Script Service. And also prevents the server from accessing anything in a player's PlayerGui. Of course, replicated storage exists as a way to store things both the client and server are supposed to see, such as remote events and remote functions

Remotes


Currently, two of the main ways of Client-Server communication are the remote function and the remote event. A remote event has three functions and two events, those being :FireServer(), :FireClient(), :FireAllClients(),OnServerEvent() and OnClientEvent respectively. The FireServer function and OnServerEvent event are used for Client to server communication while FirClient, FireAllClients, and OnClientEvent are used for Server to client communications

Remote functions are a bit more complicating to some people, as they only have 2 functions and 2 callbacks, those being :InvokeServer, :InvokeClient,OnServerInvoke and OnClientInvoke

invokeServer and OnServerInvoke are used for Client to server communications while InvokeClient and OnClientInvoke are used for Server to Client communications

A couple of other things to note, the FireClient and InvokeClient functions require a player parameter , which OnServerEvent and OnServerInvoke has "built in" player arguments, so sending the player object over isn't necessary, nor advised

Examples


--Client
local remote = game.ReplicatedStorage.RE
remote:FireServer("woo", "khanovich", "builderman")--sents woo, khanovich, and builderman over
remote.OnClientEvent:Connect(function(...)--... gives a tuple of arguments
    print(...)
end)
--Server
local remote = game.ReplicatedStorage.RE
remote.OnServerEvent:Connect(function(plr,...)--... gives a tuple of arguments
    print(plr.Name.." sent:",...)
    remote:FireClient(plr,"oof","ree","ding")--sends oof, ree and ding over 
end)

and

local remote = game.ReplicatedStorage.RF
local name = remote:InvokeServer("Cheese")
print(name)
--server
local remote = game.ReplicatedStorage.RF
remote.OnServerInvoke = function(plr,thing)
    print(plr.Name.."_"..thing)
end)

Fixing the issue


With the basics laid out, let's get to fixing your script(s)

A couple of things that you do wrong,

1: using a value instead of reference for cash check out Incapaxion's answer here

2:Not making your script FE friendly,

3.not using waitForChild on something instanced after the game starts

with all said, here it is:

local tool = script.Parent
local plr = game.Players.LocalPlayer
local ls = plr:WaitForChild("leaderstats")
local re = game.ReplicatedStorage.RemoteEvent

function onActivation()
    re:FireServer("IncreaseMoney")
end

tool.Activated:Connect(onActivation)

--server

local re = game.ReplicatedStorage.RemoteEvent

re.OnServerEvent:Connect(function(plr,action)
    if action == "IncreaseMoney" then
        plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 1
    end
end)

Hopefully this helped you along, and have a wonderful day

0
Hello! I've tried this script but I've had no luck. Does work only on studio? Thanks anyway. AidanTES 36 — 5y
0
this is just an example, for it to work, you need a remote event in replicated storage theking48989987 2147 — 5y
Ad

Answer this question