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
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Script only working in studio....

Previous Thread :: Next Thread 
TheBlazingMinatour is not online. TheBlazingMinatour
Joined: 13 Nov 2014
Total Posts: 40
09 Jan 2017 11:10 AM
*This is a re-post because i worded the last one incorrectly....



For some reason, this shop buying script doesn't work unless played through studio. When pressed, The button subtracts the money as if the item was bought and everything, but just does not give you the actual bought item.

Would i have to edit this script in any way to make it properly working in mobile? Thanks! Help is greatly appreciated:)

local cost = 20

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
local Leaderstats = player:FindFirstChild("leaderstats")
if Leaderstats then
local money = Leaderstats:FindFirstChild("Money")
if money.Value >= cost then
money.Value = money.Value - cost
local item = game.ServerStorage.ShopCatalog.DogePet:Clone()
item.Parent = player.Backpack
end
end
end)
Report Abuse
C_Sharper is online. C_Sharper
Joined: 03 Oct 2011
Total Posts: 6405
09 Jan 2017 11:27 AM
I spotted the error.

You can't access ServerStorage with a LocalScript. Try putting the item into ReplicatedStorage instead, or use a server script.


^_^
Report Abuse
BIueNarwhaI is not online. BIueNarwhaI
Joined: 10 Apr 2012
Total Posts: 866
09 Jan 2017 11:29 AM
You can press ## in Play Mode to open up the Dev Console which shows all the errors client+serversided. Idk if you can get this on mobile. But if you say it only works in studio worth doing this on a pc. Cause I don't see anything wrong with the script above. So I'd think it was an error elsewhere. Ohhhhh wait nvm. If you have FE on, you can't access Serversided objects from client scripts. Such as server storage. So you'd have to do what you're doing with RemoteEvents. To tell a server sided script to give the DogePet to the appropriate player. Google "Scripting Helpers" to find a "better" forum - http://wiki.roblox.com/index.php?title=AllTutorials - http://wiki.roblox.com/index.php?title=API:Class_reference - Google "Programming in Lua" for The book
Report Abuse
BIueNarwhaI is not online. BIueNarwhaI
Joined: 10 Apr 2012
Total Posts: 866
09 Jan 2017 11:30 AM
tfw ROBLOX removes all the reply's formatting. Thanks ROBLOX! :D


Google "Scripting Helpers" to find a "better" forum - http://wiki.roblox.com/index.php?title=AllTutorials - http://wiki.roblox.com/index.php?title=API:Class_reference - Google "Programming in Lua" for The book
Report Abuse
TheBlazingMinatour is not online. TheBlazingMinatour
Joined: 13 Nov 2014
Total Posts: 40
09 Jan 2017 04:45 PM
Thanks everyone! Had no clue of the separate functionalities of local and server-sided scripts! :)
Report Abuse
BIueNarwhaI is not online. BIueNarwhaI
Joined: 10 Apr 2012
Total Posts: 866
09 Jan 2017 05:06 PM
I think this is only a restriction when your game is using Filtering Enabled. Of which I suggest almost every game to do.


Google "Scripting Helpers" to find a "better" forum - http://wiki.roblox.com/index.php?title=AllTutorials - http://wiki.roblox.com/index.php?title=API:Class_reference - Google "Programming in Lua" for The book
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