|
I have been making a tycoon and what I wanted to do was to make it so I had to change the most minimal things if I wanted to add things. (This is a script that "collects" ores)
ores = game.Lighting:FindFirstChild("Ore")
thiss = script.Parent.Parent.Parent.Parent
name = script.Parent.Parent
function onTouched(hit)
this = ores:FindFirstChild(hit.Name)
if this then
if this.Name == hit.Name then
ore = thiss:FindFirstChild(hit.Name)
ore.Value = ore.Value + 1
name.Name = hit.Name..": "..ore.Value
hit:remove()
end
else
print("No Touchy")
end
end
script.Parent.Touched:connect(onTouched)
What it does is find the name of the ore, then find the ore IntValue within the tycoon itself and adds +1 to it. I'm pretty sure I coded it to be as little as it could be to do everything I want/need it to do for now. |
|
|
NOOO NO NO NO WTF GIVE ME YOUR ASTRA YOU DUMB ASS
local ores = game.Lighting:FindFirstChild("Ore")
local name = script.Parent.Parent
local thiss = name.Parent.Parent
script.Parent.Touched:connect(function(hit)
local this = ores:FindFirstChild(hit.Name)
if this then
local ore = thiss:FindFirstChild(hit.Name)
ore.Value = ore.Value + 1
name.Name = hit.Name..": "..ore.Value
hit:Destroy()
end
end) |
|
amandaJoin Date: 2006-11-21 Post Count: 5925 |
This is confusing. The variable names are not very clear of what they represent, you shouldn't store things in Lighting, but in ServerStorage.
I am fairly sure you have one or two checks that are completely unnecessary, however I cannot re-write your code to be the best it can be because I don't know exactly what your variables are. |
|
|
May I ask why ServerStorage is preferred over Lighting?
Is there any benefits over one or the other?
I personally prefer lighting because it was the way to do it for a long time and I never had any problems with it yet. |
|
|
Also.. Here..
ores = game.Lighting:FindFirstChild("Ore")
thiss = script.Parent.Parent.Parent.Parent
name = script.Parent.Parent
function onTouched(hit)
this = ores:FindFirstChild(hit.Name)
if this then -- This detects if it was a ore.
if this.Name == hit.Name then -- This detects if it's the correct ore
ore = thiss:FindFirstChild(hit.Name)
ore.Value = ore.Value + 1
name.Name = hit.Name..": "..ore.Value
hit:remove()
end
else -- This is incase it isn't an ore.
print("No Touchy")
end
end
script.Parent.Touched:connect(onTouched) |
|
|
|
Abstract, if you are going to say something. Please explain why. Otherwise it's a useless spam comment. |
|
amandaJoin Date: 2006-11-21 Post Count: 5925 |
@lomo, because ServerStorage was specifically created for that purpose, to hold models and other server-stuff.
Read the second paragraph down on this link:
http://wiki.roblox.com/index.php?title=API:Class/Lighting
Also, you will get better help here if you are up to date in best practices. |
|
|
The Lighting service controls all of the environmental variables in a map, including the colors of light, time of day, angle of celestial bodies, etc.
The Lighting service was commonly used for storage since scripts did not run and models weren't rendered. However, ServerStorage and ReplicatedStorage should now be used for this purpose instead. |
|
|
Okay, I read a bit on that. I never really had a problem with lighting considering I never noticed anything wrong with it.
So generally speaking I should be using ServerStorage and not ReplicatedStorage unless I want to do stuff that isn't directly only related to the client/server? |
|