|
| 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
|
  |
| 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 |
|
|
|
| 17 Aug 2016 12:05 PM |
| http://wiki.roblox.com/index.php?title=Variable#Global_Variables |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 17 Aug 2016 12:13 PM |
| Yes, I know. I'm just making it compatible with his script. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 17 Aug 2016 12:15 PM |
| ^ I copied and pasted both of the scripts into the correct objects, and nothing worked. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 12:17 PM |
| Brb. Going to fix the method then. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 18 Aug 2016 12:13 PM |
| mmk, I'll try that later <3 |
|
|
| Report Abuse |
|
|
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 |
|
|