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

Cash.Value wont update but Subscribers.Value will?

Asked by 5 years ago
script.Parent.Touched:Connect(function()
    game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 1
end)

Cash

script.Parent.Parent.A.B.MouseButton1Click:Connect(function()
    local waitTime = math.random(3,5)
    local subscriberAdd = math.random(1,3)

     while true do
        wait(waitTime)
        game.Players.LocalPlayer.leaderstats.Subscribers.Value =  game.Players.LocalPlayer.leaderstats.Subscribers.Value + subscriberAdd
        wait(2)
    end
end)

A and B are added in because I dont want game idea stolen

Even when I do the same thing in the same script cash dosen't work

0
These scripts are doing two different things. What are you trying to do? Are there any errors? royaltoe 5144 — 5y
0
No errors.. That is what I am saying, the subscribe one works but the cash one dosen't and I dont know why CoreMcNugget 15 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I'm assuming that the first one is in a localscript, as it references the part as script. Parent. You would have to make it a localscript to index localplayer, so here is my solution.

loccal plr=game.Players.LocalPlayer
local cash=pls.leaderstats.Cash.Value
local part=--your part
script.Parent.Touched:Connect(function()
    cash.Value = Cash.Value + 1
end)
0
The script goes inside a part in screengui EmbeddedHorror 299 — 5y
0
This isn’t suggestible in 2019. LocalScript can’t change objects sahadeed 87 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

This is definitely not how this is supposed to be done. There are 4 things you need to know.

  1. LocalPlayer can only be accessed from LocalScript. This makes sense as the server script does not know which player you are pointing at. If someone on the phone asks who am I, then it would not make sense to say “Me” since “Me” could be said by anyone. You need to remember the server script as an omnipotent Roman god which is not associated with any player.

  2. All changes made to the game MUST BE DONE ON SERVER SCRIPT. You can not make any changes from localscript. Localscript is for the mortals, Script is for the gods. Use LocalScript for GUIs and input.

  3. Use remote functions and events (https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events). The server won’t hold everybody’s hands, so it is your responsibility to send data through remotes from their source to where they are needed. For example: you generate an array of randomly generated terrain from the server. It is your job to push those keys and do idiotRemote:InvokeClient(player, stuff, stuff), so that the array gets visualized on client.

  4. Use OOP. Object oriented programming is the act of processing objects to get all kinds of data without repeating yourself. OOP is so prevalent there is a Wikipedia article on it. OOP is your friend. Do not abandon it. Right now your code is good but I guarantee that if you keep adding features without ModuleScripts, your code will turn into an illegible, inefficient, pile of mess.

If you follow these 4 pieces of advice then you have a good chance at becoming featured. I personally have never hit the front page in so long. Back then it was much easier

0
Hello. Did this help? If yes, then accept an answer. This will help others find the right questions and answers to help their scripting career sahadeed 87 — 5y
0
Did not fully answer my question but yes it did help. I was using part because I wanted to see if it was working with a part. My actual script goes that if the viewers value is under 10 then add 1 dollar every certain amount of seconds. Ill up vote your reply// CoreMcNugget 15 — 5y
0
So did it work? sahadeed 87 — 5y

Answer this question