raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 25 Aug 2015 07:38 PM |
Hi guys,
I am not a good scripter, and I need help with some shop GUI scripts.
player = script.Parent.Parent.Parent.Parent.Parent money = player.leaderstats.Coins price = 50 tool = game.Lighting:findFirstChild("BasicShortsword")
function buy() if money.Value >= price then money.Value = money.Value - price local a = tool:clone() a.Parent = player.Backpack local b = tool:clone() b.Parent = player.StarterGear
end end script.Parent.MouseButton1Down:connect(buy)
Now, I have a tool named "BasicShortsword" in Lighting. And I set my leaderstats money to Coins. The most weird thing of all, the script worked a few hours ago. I was trying to add more tools to buy the same way. And it stopped working. The output says: "leaderstats is not a valid member of PlayerGui". I will release the not working shop GUI as a free model, so someone can fix and release it without bothering on the forums.
By the way, the shop GUI is inspired by LU. |
|
|
| Report Abuse |
|
|
Famion
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 1043 |
|
|
| 25 Aug 2015 07:41 PM |
| do a waitforchild for the leaderstats |
|
|
| Report Abuse |
|
|
|
| 25 Aug 2015 07:41 PM |
local player = game.Players.LocalPlayer
|
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 25 Aug 2015 07:45 PM |
local player = game.Players.LocalPlayer line works for now. Thanks.
|
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 25 Aug 2015 07:49 PM |
| Aaand... nope. That line woks on Studio testing only, and not on the game. |
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 25 Aug 2015 07:59 PM |
It still doesn't work. Tried:
local player = game.Players.LocalPlayer local money = player.leaderstats:WaitForChild("Coins") price = 50 tool = game.Lighting:findFirstChild("BasicShortsword")
function buy() if money.Value >= price then money.Value = money.Value - price local a = tool:clone() a.Parent = player.Backpack local b = tool:clone() b.Parent = player.StarterGear
end end script.Parent.MouseButton1Down:connect(buy)
WaitForChild won't make a differance. local player only works on Studio. ROBLOX can be very unstable. |
|
|
| Report Abuse |
|
|
Famion
|
  |
| Joined: 29 Nov 2008 |
| Total Posts: 1043 |
|
|
| 25 Aug 2015 08:40 PM |
local player = game.Players.LocalPlayer local money = player:WaitForChild("leaderstats"):WaitForChild("Coins") price = 50 tool = game.Lighting:WaitForChild("BasicShortsword")
function buy() if money.Value >= price then money.Value = money.Value - price local a = tool:clone() a.Parent = player.Backpack local b = tool:clone() b:Clone().Parent = player.StarterGear b:Clone().Parent = player.Backpack player.Character:BreakJoints() end end script.Parent.MouseButton1Down:connect(buy) |
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 25 Aug 2015 09:07 PM |
The player dies when I try to buy the item in the studio. Nothing happens when I try on the online game. |
|
|
| Report Abuse |
|
|
|
| 25 Aug 2015 09:24 PM |
| make sure you are using a localscript noob |
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 26 Aug 2015 06:42 AM |
| The player dies when I try to buy the item in both Studio and the game. Tried Famion's script with LocalScript. And it still does nothing in the online place. |
|
|
| Report Abuse |
|
|
rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
| |
|
rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
|
| 26 Aug 2015 07:03 AM |
local player = game.Players.LocalPlayer local money = player:WaitForChild("leaderstats"):WaitForChild("Coins") localprice = 50 local tool = game.Lighting:WaitForChild("BasicShortsword")
function buy() if money.Value >= price then money.Value = money.Value - price local a = tool:Clone() a.Parent = player.StarterPack player.Character:BreakJoints() end end
script.Parent.MouseButton1Down:connect(buy) |
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 26 Aug 2015 07:18 AM |
QPaint Started 15:10:45.353 - TestService: zars15's real time CFrame loaded 15:10:47.198 - DataModel Loading http://www.roblox.com/asset/?id=287864911 15:10:47.351 - Mode 2 failed: "Unable to create D3D device: 887a0004" 15:10:47.352 - Trying mode 3... 15:11:05.809 - Auto-Saving... QPaint Started 15:11:06.601 - TestService: zars15's real time CFrame loaded 15:11:07.072 - leaderstats is not a valid member of DataModel 15:11:07.072 - Script 'Workspace.LU Shop GUI v1.0.Frame.Item 6.Main', Line 2 15:11:07.073 - Stack End 15:11:07.689 - leaderstats is not a valid member of PlayerGui 15:11:07.689 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 19.Main', Line 2 15:11:07.690 - Stack End 15:11:07.690 - leaderstats is not a valid member of PlayerGui 15:11:07.691 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 18.Main', Line 2 15:11:07.691 - Stack End 15:11:07.692 - leaderstats is not a valid member of PlayerGui 15:11:07.692 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 7.Main', Line 2 15:11:07.692 - Stack End 15:11:07.693 - leaderstats is not a valid member of PlayerGui 15:11:07.693 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 8.Main', Line 2 15:11:07.694 - Stack End 15:11:07.694 - leaderstats is not a valid member of PlayerGui 15:11:07.694 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 9.Main', Line 2 15:11:07.695 - Stack End 15:11:07.695 - leaderstats is not a valid member of PlayerGui 15:11:07.695 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 10.Main', Line 2 15:11:07.696 - Stack End 15:11:07.697 - leaderstats is not a valid member of PlayerGui 15:11:07.697 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 11.Main', Line 2 15:11:07.697 - Stack End 15:11:07.698 - leaderstats is not a valid member of PlayerGui 15:11:07.699 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 12.Main', Line 2 15:11:07.699 - Stack End 15:11:07.700 - leaderstats is not a valid member of PlayerGui 15:11:07.700 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 13.Main', Line 2 15:11:07.700 - Stack End 15:11:07.701 - leaderstats is not a valid member of PlayerGui 15:11:07.702 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 14.Main', Line 2 15:11:07.702 - Stack End 15:11:07.703 - leaderstats is not a valid member of PlayerGui 15:11:07.704 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 15.Main', Line 2 15:11:07.704 - Stack End 15:11:07.705 - leaderstats is not a valid member of PlayerGui 15:11:07.705 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 16.Main', Line 2 15:11:07.706 - Stack End 15:11:07.706 - leaderstats is not a valid member of PlayerGui 15:11:07.706 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 17.Main', Line 2 15:11:07.707 - Stack End 15:11:12.760 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:12.761 - Stack Begin 15:11:12.761 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:12.761 - Stack End 15:11:13.728 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:13.728 - Stack Begin 15:11:13.729 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:13.729 - Stack End 15:11:14.179 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:14.179 - Stack Begin 15:11:14.180 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:14.180 - Stack End 15:11:14.817 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:14.818 - Stack Begin 15:11:14.818 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:14.818 - Stack End 15:11:15.617 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:15.617 - Stack Begin 15:11:15.618 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:15.618 - Stack End 15:11:16.321 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:16.321 - Stack Begin 15:11:16.322 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:16.322 - Stack End 15:11:17.245 - Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main:7: attempt to compare nil with number 15:11:17.245 - Stack Begin 15:11:17.246 - Script 'Players.Player.PlayerGui.LU Scrolling Shop GUI v1.0.Frame.ScrollingFrame.Item 6.Main', Line 7 15:11:17.246 - Stack End
This is the output. Tried LocalScript. It doesn't wok on Studio or online. Should I make some changes on the leaderstats too?
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") --We create a new IntValue money.Name = "Coins" --this is the name you want the leader-stat to be when it shows up in-game. money.Value = 250000000 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later) money.Parent = leaderstats -- Set the money object as a child of the leaderstats object. end) |
|
|
| Report Abuse |
|
|
rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
|
| 26 Aug 2015 09:43 AM |
Okay found the solution (Works fine for me on studio):
On the textbutton on a localscript:
local player = game.Players.LocalPlayer local money = player:WaitForChild("leaderstats"):WaitForChild("Coins") local price = 50 local tool = game.Lighting:WaitForChild("BasicShortsword")
function buy() if money.Value >= price then money.Value = money.Value - price local a = tool:Clone() a.Parent = player.StarterGear player.Character:BreakJoints() end end
script.Parent.MouseButton1Down:connect(buy)
Leaderboard on a server script:
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "Coins" money.Value = 250000000 money.Parent = leaderstats end)
|
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 26 Aug 2015 11:18 AM |
19:13:50.916 - leaderstats is not a valid member of PlayerGui
Nothing happens. Tried to put shop GUI Script on a LocalScript and leaderstats on Workspace and ServerScriptStorage, and I still get this eroor on output. I guess my problem will be fixed when I handle this, but I have no idea about how to do it. I am a noob when it comes to scripting, alright. |
|
|
| Report Abuse |
|
|
rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
|
| 26 Aug 2015 11:53 AM |
Leaderboard MUST be on workspace only. The shop GUI script must be on a textbutton only.
This is how you need to put the scripts:
Workspace Leaderboard script -Scripts and stuff
StarterGui ScreenGui TextButton Shop Gui localscript |
|
|
| Report Abuse |
|
|
rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
|
| 26 Aug 2015 11:54 AM |
| Also for me works fine on studio. |
|
|
| Report Abuse |
|
|
raxor34
|
  |
| Joined: 11 Feb 2013 |
| Total Posts: 22 |
|
|
| 26 Aug 2015 12:22 PM |
Hmmm... The script is in
StarterGUI ScreenGUI Frame Frame Scrolling Frame Item6 LocalScript Close Button
That means I should rearrange the GUI all over again. I might try it later. But the weird thing is, The regular script in TextButton worked yesterday without WaitForChild or anything like that. |
|
|
| Report Abuse |
|
|