generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I find a stat?

Previous Thread :: Next Thread 
ultrabinblox1 is not online. ultrabinblox1
Joined: 25 Jan 2011
Total Posts: 536
17 Aug 2016 12:00 PM
I'm trying to make a cash giver button, but how to I find a stat from another script?
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
17 Aug 2016 12:03 PM
Where is your stat located?
Are you talking about like, a leaderstat or an IntValue/NumberValue? Or a variable in another script?


Report Abuse
TheIceZombieSlayer is online. TheIceZombieSlayer
Joined: 26 Mar 2013
Total Posts: 267
17 Aug 2016 12:05 PM
http://wiki.roblox.com/index.php?title=Variable#Global_Variables
Report Abuse
ultrabinblox1 is not online. ultrabinblox1
Joined: 25 Jan 2011
Total Posts: 536
17 Aug 2016 12:05 PM
It's a variable in another script that is a local script. Do I need to change this to a normal script? I have the stat displayed in a textlabel.

money = Instance.new("IntValue")
money.Name = "cash"
money.Parent = game.Workspace
money.Value = 10
label = script.Parent.TextLabel
label.Text = "Cash " ..money.Value

That's the script in the GUI.
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
17 Aug 2016 12:07 PM
you should not be creating sensitive values like that on the client to begin with

guis should only be a representation of what is created on the server




Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
TheIceZombieSlayer is online. TheIceZombieSlayer
Joined: 26 Mar 2013
Total Posts: 267
17 Aug 2016 12:10 PM
--SCRIPT INSIDE THE GUI

money = Instance.new("IntValue")
money.Name = "cash"
money.Parent = script.Parent
money.Value = 10
label = script.Parent.TextLabel

money.Changed:connect(function ()
label.Text = "Cash " ..money.Value
end)

function game.Workspace.GetCash.OnClientInvoke()
return money.Value
end

--SCRIPT INSIDE THE BUTTON

script.Parent.Touched:connect(function (hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
local cash = game.Workspace.GetCash:InvokeClient(player)
print(player.Name .. " has " .. cash)
end
end
end)
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
17 Aug 2016 12:11 PM
@Zombie

once again that's a very bad method

don't create player stats in a client sided script


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
TheIceZombieSlayer is online. TheIceZombieSlayer
Joined: 26 Mar 2013
Total Posts: 267
17 Aug 2016 12:12 PM
I forgot to say add a line

--IN THE GUI

money = Instance.new("IntValue")
money.Name = "cash"
money.Parent = script.Parent
money.Value = 10
label = script.Parent.TextLabel

money.Changed:connect(function ()
label.Text = "Cash " ..money.Value
end)

function game.Workspace.GetCash.OnClientInvoke()
return money.Value
end

--SCRIPT INSIDE THE BUTTON
Instance.new("RemoteEvent", workspace).Name = "GetCash"
script.Parent.Touched:connect(function (hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
local cash = game.Workspace.GetCash:InvokeClient(player)
print(player.Name .. " has " .. cash)
end
end
end)
Report Abuse
TheIceZombieSlayer is online. TheIceZombieSlayer
Joined: 26 Mar 2013
Total Posts: 267
17 Aug 2016 12:13 PM
Yes, I know. I'm just making it compatible with his script.
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
17 Aug 2016 12:14 PM
why would you make it compatible with an already broken way of logic

come on man


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
ultrabinblox1 is not online. ultrabinblox1
Joined: 25 Jan 2011
Total Posts: 536
17 Aug 2016 12:15 PM
^ I copied and pasted both of the scripts into the correct objects, and nothing worked.
Report Abuse
TheIceZombieSlayer is online. TheIceZombieSlayer
Joined: 26 Mar 2013
Total Posts: 267
17 Aug 2016 12:17 PM
Brb. Going to fix the method then.
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
17 Aug 2016 12:19 PM
make the stat when the player is added and then fire that specific client to represent what the server created

game.Players.PlayerAdded:connect(function(player)
--make cash stat
game.ReplicatedStorage.YourRemoteEventHere:FireClient(player,cash.Value)

then in a localscript

game.ReplicatedStorage.YourRemoteEventHere.OnClientEvent:connect(function(cashValue)
script.Parent.Text = "Cash: "..cashValue
end)

then, every time the value is changed have the client represent it

this would still be inside of the PlayerAdded function

cash.Changed:connect(function(val)
:FireClient(player,val)
end)

obviously you need to add a remote event to rep storage and change things accordingly

but this should work


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
TheIceZombieSlayer is online. TheIceZombieSlayer
Joined: 26 Mar 2013
Total Posts: 267
17 Aug 2016 12:23 PM
Here:

--SCRIPT INSIDE THE GUI

money = game.Players.LocalPlayer.cash
label = script.Parent.TextLabel

label.Text = "Cash " ..tostring(money.Value)

money.Changed:connect(function ()
label.Text = "Cash " ..tostring(money.Value)
end)




--SCRIPT INSIDE THE BUTTON
script.Parent.Touched:connect(function (hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
local cash = player.cash.Value
print(player.Name .. " has " .. tostring(cash) .. " cash.")
end
end
end)




--SCRIPT INSIDE game.ServerScriptService

game.Players.PlayerAdded:connect(function (player)
local money = Instance.new("IntValue", player)
money.Name = "cash"
money.Value = 10
end)
Report Abuse
ultrabinblox1 is not online. ultrabinblox1
Joined: 25 Jan 2011
Total Posts: 536
17 Aug 2016 12:28 PM
^ Still not working.
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
17 Aug 2016 04:04 PM
i already told you how to do it

all values that you're going to save should be created SERVER SIDE

what the client sees on the gui is just mimicry of what the server's value is




Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
ultrabinblox1 is not online. ultrabinblox1
Joined: 25 Jan 2011
Total Posts: 536
18 Aug 2016 10:35 AM
^ I'm only a beginner scripter and do not understand how to that or what it means. Sorry if I sound stupidly dumb.
Report Abuse
WrightPhillips99 is not online. WrightPhillips99
Joined: 27 Jun 2015
Total Posts: 667
18 Aug 2016 10:38 AM
you can make a clickdetector function and make money.Value = money.Value + 20
that should work and if not your out of luck buddy
Report Abuse
ultrabinblox1 is not online. ultrabinblox1
Joined: 25 Jan 2011
Total Posts: 536
18 Aug 2016 12:13 PM
mmk, I'll try that later <3
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Aug 2016 12:17 PM
local button = script.Parent

local Amount = 50

button.ClickDetector.MouseClick:connect(function(player)
local stats = player:WaitForChild('leaderstats')
local cash = stats:WaitForChild('Cash')
cash.Value = cash.Value + Amount
end)


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image