Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why doesnt this script work?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I was trying to make it clone the coin that was picked and cloned to the workspace and it didnt work...

--[[
script.Parent.BrickColor = BrickColor.new(colors[math.random(1, #colors)]
Scripted by Dreamingrocky/UltraUnitMode.    
--]] 
local Coins = game.ServerStorage.Coins
local CoinsNames = {
"BronzeCoin",
"GoldCoin",
"SilverCoin",
}

local Positions = {
-154.1, 1.1, 86.9,
-170.1, 1.1, 61.9,
-132.1, 1.1, 63.9,
-144.1, 1.1, 46.9,
-172.1, 1.1, 36.9,
}


while true do
for i,v in pairs(Coins.FolderCoins:GetChildren()do
wait(0.5)
if Coins.Name == CoinsName[math.random(1, #CoinsNames)]then
Coins.Position = Vector3.new(Positions[math.random(1, #CoinsNames)])
x = Coins:Clone()
x.Parent = game.Workspace
end

end
end
end



2 answers

Log in to vote
1
Answered by
Kurieita 125
8 years ago

Your error is how your storing the positions

--[[
script.Parent.BrickColor = BrickColor.new(colors[math.random(1, #colors)]
Scripted by Dreamingrocky/UltraUnitMode.    
--]] 
local Coins = game.ServerStorage.Coins
local CoinsNames = {
"BronzeCoin",
"GoldCoin",
"SilverCoin",
}

local Positions = {
Vector3.new(-154.1, 1.1, 86.9),
Vector3.new(-170.1, 1.1, 61.9),
Vector3.new(-132.1, 1.1, 63.9),
Vector3.new(-144.1, 1.1, 46.9),
Vector3.new(-172.1, 1.1, 36.9),
} --[[ A new line doesn't actually mean something, whitespaces are ignore in Lua


while true do
for i,v in pairs(Coins.FolderCoins:GetChildren()do
wait(0.5)
if Coins.Name == CoinsName[math.random(1, #CoinsNames)]then
Coins.Position = Positions[math.random(1, #CoinsNames)]
x = Coins:Clone()
x.Parent = game.Workspace
end

end
end
end

Your problem was that the interpreter thought that you were storing a double type number, meaning a number with a decimal. While in reality you wanted the interpreter to return Vector3 values.

To sum it up

Lua thought this:

Coins.Position = 54.33

While you actually wanted

Coints.Position = Vector3.new(0, 0, 0)

Also, I noticed your code have some syntax errors plus other interpreted errors. Take a look at your code:

--[[
script.Parent.BrickColor = BrickColor.new(colors[math.random(1, #colors)]
Scripted by Dreamingrocky/UltraUnitMode.    
--]] 
local Coins = game.ServerStorage.Coins
local CoinsNames = {
"BronzeCoin",
"GoldCoin",
"SilverCoin",
}

local Positions = {
-154.1, 1.1, 86.9,
-170.1, 1.1, 61.9,
-132.1, 1.1, 63.9,
-144.1, 1.1, 46.9,
-172.1, 1.1, 36.9,
}


while true do
for i,v in pairs(Coins.FolderCoins:GetChildren()do
wait(0.5)
if Coins.Name == CoinsName[math.random(1, #CoinsNames)]then
Coins.Position = Vector3.new(Positions[math.random(1, #CoinsNames)])
x = Coins:Clone()
x.Parent = game.Workspace
end

end
end
end

And take a look at my:

--[[
script.Parent.BrickColor = BrickColor.new(colors[math.random(1, #colors)]
Scripted by Dreamingrocky/UltraUnitMode.    
--]] 
local Coins = game.ServerStorage.Coins
local CoinsNames = {
"BronzeCoin",
"GoldCoin",
"SilverCoin",
}

local Positions = {
Vector3.new(-154.1, 1.1, 86.9),
Vector3.new(-170.1, 1.1, 61.9),
Vector3.new(-132.1, 1.1, 63.9),
Vector3.new(-144.1, 1.1, 46.9),
Vector3.new(-172.1, 1.1, 36.9),
}


while true do
for i,v in pairs(Coins.FolderCoins:GetChildren()do
if v.Name == CoinsName[math.random(1, #CoinsNames)] then
wait(0.5)
local coin = v:Clone()
coin.Parent = workspace
coin.Position = Vector3.new(Positions[math.random(1, #CoinsNames)])
end
end
end

If this help please vote up and as accepted, if it doesn't let me know and I'll help more. :)

0
Kurieita I have copied the script that you have made and saw the script and i went over it. But i doesnt work, also the output doesnt have any errors. UltraUnitMode 419 — 8y
0
Try debugging, meaning put print("A"), print("B") and so on around the whole script, and see which one prints and which one doesn't. Let me know which line and I be more than happy to take a look. Kurieita 125 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Another error. Change this:

for i,v in pairs(Coins.FolderCoins:GetChildren()do

To:

for i,v in pairs(Coins.FolderCoins:GetChildren()) do
0
Yes, that was one of the syntax error. I thought I posted it, guess not. Kurieita 125 — 8y

Answer this question