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 » Scripting Helpers
Home Search
 

Re: Would This Create Problems?

Previous Thread :: Next Thread 
rowerowe71 is not online. rowerowe71
Joined: 14 Apr 2013
Total Posts: 1999
22 Jun 2014 06:20 AM
Would this create problems because there are so many if statements and different combinations...

And by problem I mean not allowing the script to work properly.

function onClicked(player)
if Workspace:FindFirstChild("Strawberries") and Workspace:FindFirstChild("Milk")then
wait(5.4)
game.Workspace.Milk:Remove()
game.Workspace.Strawberries:Remove()
game.Lighting.StrawberrySwirl:Clone().Parent = game.Workspace
local message = Instance.new("Hint")
message.Parent = game.Workspace
message.Text = "You made a strawberry swirl smoothie!"
wait(3)
message:Remove()
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked(player)
if Workspace:FindFirstChild("Blueberries") and Workspace:FindFirstChild("Milk")then
wait(5.4)
game.Workspace.Milk:Remove()
game.Workspace.Blueberries:Remove()
game.Lighting.BlueberrySplash:Clone().Parent = game.Workspace
local message = Instance.new("Hint")
message.Parent = game.Workspace
message.Text = "You made a blueberry splash smoothie!"
wait(3)
message:Remove()
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked(player)
if Workspace:FindFirstChild("Milk") then
wait(5.4)
game.Workspace.Milk:Remove()
game.Lighting.Milk:Clone().Parent = game.Workspace
local message = Instance.new("Hint")
message.Parent = game.Workspace
message.Text = "You made plain milk!"
wait(3)
message:Remove()
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked(player)
if Workspace:FindFirstChild("Strawberries") then
wait(5.4)
game.Workspace.Strawberries:Remove()
game.Lighting.BlendedStrawberries:Clone().Parent = game.Workspace
local message = Instance.new("Hint")
message.Parent = game.Workspace
message.Text = "You made crushed strawberries!"
wait(3)
message:Remove()
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked(player)
if Workspace:FindFirstChild("Blueberries") then
wait(5.4)
game.Workspace.Blueberries:Remove()
game.Lighting.BlendedBlueberries:Clone().Parent = game.Workspace
local message = Instance.new("Hint")
message.Parent = game.Workspace
message.Text = "You made some blended blueberries!"
wait(3)
message:Remove()
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked(player)
if Workspace:FindFirstChild("Bananas") then
wait(5.4)
game.Workspace.Bananas:Remove()
game.Lighting.BlendedBananas:Clone().Parent = game.Workspace
local message = Instance.new("Hint")
message.Parent = game.Workspace
message.Text = "You made sliced bananas!"
wait(3)
message:Remove()
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)


Report Abuse
rowerowe71 is not online. rowerowe71
Joined: 14 Apr 2013
Total Posts: 1999
22 Jun 2014 06:25 AM
I'm pretty sure I need to come up with a new way to do this...

Anyone have any ideas?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
22 Jun 2014 06:35 AM
Fruits = {["Strawberries"] = "crushed",["Bananas"] = "sliced",["Blueberries"] = "blended"}

script.Parent.MouseClick:connect(function()
for i,v in pairs(Fruits) do
if Workspace:FindFirstChild(i) then
wait(5.4)
Workspace[i]:Destroy()
Message = Instance.new("Hint",Workspace)
game:GetService("Debris"):AddItem(Message,3)
Message.Text = "You made" .. v .. i .. "!"
end
end
end)
Report Abuse
rowerowe71 is not online. rowerowe71
Joined: 14 Apr 2013
Total Posts: 1999
22 Jun 2014 06:36 AM
Can you explain this to me?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
22 Jun 2014 06:43 AM
Fruits = {["Strawberries"] = "crushed",["Bananas"] = "sliced",["Blueberries"] = "blended"}
>Dictionary with index set to the fruit, value set to the type you'd create.
http://wiki.roblox.com/index.php?title=Dictionary#Dictionaries

script.Parent.MouseClick:connect(function()
Generic/Anonymous function
http://wiki.roblox.com/index.php?title=Function#Dictionaries

for i,v in pairs(Fruits) do
>For loop looking through each item in the table one at a time
http://wiki.roblox.com/index.php?title=Generic_for

if Workspace:FindFirstChild(i) then
>Standard if statement using the index returned from the table
Not bothering to link this.

wait(5.4)
>Your wait time
Derp

Workspace[i]:Destroy()
>Destroying item should the if statement return true. Use Destroy rather then Remove if you don't plan to use the object again.
Not going to link

Message = Instance.new("Hint",Workspace)
>Creating the message.
No link. You clearly know this part.

game:GetService("Debris"):AddItem(Message,3)
>Debris is more reliable.
http://wiki.roblox.com/index.php?title=Service
http://wiki.roblox.com/index.php?title=Debris

Message.Text = "You made" .. v .. i .. "!"
>Changing the text to the Value in the table then the Index.

end
end
end)
Report Abuse
rowerowe71 is not online. rowerowe71
Joined: 14 Apr 2013
Total Posts: 1999
22 Jun 2014 06:46 AM
I just don't understand how the message text part would work the way it used to.
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
22 Jun 2014 06:50 AM
Fruits = {["Strawberries"] = "crushed",["Bananas"] = "sliced",["Blueberries"] = "blended"}
Message.Text = "You made" .. v .. i .. "!"

Let's say you were looking at the first one.

v would be "crushed" and i would be "strawberries"

The text would be:
"You made" .. "crushed" .. "Strawberries" .. !
or
You madecrushedStrawberries!

So you could actually put some spaces...
Report Abuse
rowerowe71 is not online. rowerowe71
Joined: 14 Apr 2013
Total Posts: 1999
22 Jun 2014 06:54 AM
But what about adding the milk and other smoothies?

Such as the strawberry swirl?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
22 Jun 2014 07:19 AM
Recipes = {
["Disaster Smoothie"] = {{"Potato","Onion","Dirt","Carrot"}, "You've made a mess!" }
}

script.Parent.MouseClick:connect(function()
for i,v in pairs(Recipes) do
HasIngredients = true
for i2,v2 in pairs(v[1]) do
if not Workspace:FindFirstChild(v2) then
HasIngredients = false
end
end
if HasIngredients then
for i2,v2 in pairs(v[1]) do
Workspace[v2]:Destroy()
end
print(v[2])
end
end
end)
Report Abuse
rowerowe71 is not online. rowerowe71
Joined: 14 Apr 2013
Total Posts: 1999
22 Jun 2014 07:59 AM
Is there any other way to do this without the tables and stuff?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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