I'm new to scripting and am generally learning basic things, but i cant figure this out. Ill explain it the best that i can understand how too!
I got 2 separate local scripts, 1 that buys the potion and increases the amount and one that keeps account of a clicks value. I will have them placed in the order i spoke of them. But in the text Button i keep the local script I keep the track/Update clickValues, I also have an intValue which is what actually stores the value of my clicks the script itself just adds rebirths value to it. The problem is when i call that int value in the local script that lets the player buy potions to multiply the click amount, the intValue doesnt change.
Local Script - Buying Potion
--Buy potions Gui/ Multiplies CLick amount local player = game.Players.LocalPlayer local clicks = player:WaitForChild("leaderstats"):WaitForChild("Clicks") local rebirths = player:WaitForChild("leaderstats"):WaitForChild("Rebirths") local gems = player:WaitForChild("leaderstats"):WaitForChild("Gems") -- tapAmount is connected to the Amount value in my click button. local tapAmount = game.StarterGui.clicksGui.Clicks.Amount.Value script.Parent.MouseButton1Click:Connect(function() --Checks to see if the player has 20 gems, if so, it multiplies the tapAmount by 2 and removes 20 gems. if gems.Value >= 20 then wait() tapAmount = tapAmount * 2 wait() gems.Value = gems.Value - 20 end --Sets button text to tell that gem amount is too low if gems.Value < 20 then tapAmount = tapAmount wait() script.Parent.Text = "Not Enough!" wait(2) script.Parent.Text = "Buy - 20 Gems" end end)
Local Script Adds clicks to the click value due to rebirths and connects the value of clicks to the click leaderstats
script.Parent.MouseButton1Click:Connect(function() local player = game.Players.LocalPlayer local clicks = player:WaitForChild("leaderstats"):WaitForChild("Clicks") local rebirths = player:WaitForChild("leaderstats"):WaitForChild("Rebirths") local amount = script.Parent.Amount.Value clicks.Value = clicks.Value + amount --adds to click value after rebirths if rebirths.Value > 0 then clicks.Value = clicks.Value + rebirths.Value end end)
Hello there!
This is an issue that many people run into while scripting. One of the safety features that ROBLOX has in place to avoid hackers is to make it so that you can't change global values from the client. This means that LocalScripts can not change an outside value because ROBLOX thinks that it is a hacker, and therefore blocks it. (I explained that badly ;-;)
So, that leaves you with 2 options that I can think of right now.
1.) Change your scripts to a regular script instead of a local script and find a new way to get the player
A lot of scripters may recommend against this because it is very sloppy, but it does work. When in the game, the GUI can be found in each individual player. The order is like this:
game.Players.(player).PlayerGui.ScreenGui....etc
Basically, the StarterGui gets cloned into the player, and then it is called "PlayerGui"
So, to get the player, you can use script.Parent.Parent.Parent.Parent... until you reach the player. It depends on how many guis you have inside of the gui with the script.
2.) This is the more efficient method, which is using a RemoteEvent.
A RemoteEvent is the way that most scripters get around this problem. You can use it to do something globally with a localscript, which is exactly what you need. I am not good at explaining, so here is a link to some helpful information.
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
When you want to change the value, you should fire a remote event to a script that changes it.
I hope this helps, and let me know if you have any further questions! I will try to answer :) ~Amanda314159