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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

What's wrong with this color-changing script?

Previous Thread :: Next Thread 
jojods1125 is not online. jojods1125
Joined: 27 Sep 2011
Total Posts: 11253
03 May 2014 07:57 PM
So I'm trying to make this brick turn into one of 3 colors when it spawns. Here's the script that I made that will determine its color:


Pellet.BrickColor = BrickColor.new("Really red") or ("Lime green") or ("Royal purple")


Whenever the brick spawns, it just turns red, and never green nor purple. Yes, "Lime green" and "Royal purple" are the correct terms. And there's no problems with the other scripts; they don't affect the color anyways.

So, does anyone know what's wrong with this? It's probably something with the "or" statements, but I'm no expert, so I'm not entirely sure.

Thanks!
Report Abuse
Discern is not online. Discern
Joined: 02 Feb 2013
Total Posts: 331
03 May 2014 08:03 PM
You are correct. "Or" is only used with if statements. Therefore, you should make a table with the colors and select one randomly.

colors = {"Really red","Lime green","Royal purple"}

randomcolor = colors[math.random(1, #colors)]
Pellet.BrickColor = BrickColor.new("" ..randomcolor.. "")
Report Abuse
jojods1125 is not online. jojods1125
Joined: 27 Sep 2011
Total Posts: 11253
03 May 2014 08:26 PM
@dis

It worked, but not exactly as I was hoping it would.

You see, the brick that spawns is shot from a gun. Each time the gun shoots, the brick will be a different color (for example, one time it'll be green, the next time it'll be red, etc.)

After I tested what you told me, the brick stayed the same color each time I shot the gun. However, it was a different color each time I ran Solo Mode.

For example, the first time I played Solo, it shot green every time. The second time I played, it shot red every time. The third time I played, it shot purple.

Is it possible for each time I shoot the gun that it becomes a different color, rather than each time I test it?
Report Abuse
Discern is not online. Discern
Joined: 02 Feb 2013
Total Posts: 331
03 May 2014 08:29 PM
Tell me the entire script.
Report Abuse
jojods1125 is not online. jojods1125
Joined: 27 Sep 2011
Total Posts: 11253
03 May 2014 08:32 PM
@dis

The top is the part that affects the color. The rest is unrelated to what I'm asking.


Tool = script.Parent
VELOCITY = 50 -- constant
loaded=false

local Pellet = Instance.new("Part")

colors = {"Really red", "Lime green", "Royal purple"}

randomcolor = colors[math.random(1, #colors)]

Pellet.Size = Vector3.new(1,1,4)
Pellet.Shape = 1
Pellet.BrickColor = BrickColor.new("" ..randomcolor.. "")
Pellet.Material = Enum.Material.SmoothPlastic
Pellet.Locked = true
Pellet.TopSurface = 0
Pellet.Transparency = 0.4
Pellet.BottomSurface = 0

script.Parent.SnowballScript:clone().Parent = Pellet





function fire(v, shootDirect)


-- find player's head pos

local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)

local head = vCharacter:findFirstChild("Head")
if head == nil then return end

Tool.Handle.Fire:Play()
local launch = head.Position + 10 * v

local missile = Pellet:clone()
missile.CFrame = CFrame.new(launch,shootDirect)
missile.Position = launch
missile.Velocity = v * 60

local force = Instance.new("BodyForce")
force.force = Vector3.new(0,942,0)
force.Parent = missile

missile.SnowballScript.Disabled = false


missile.Parent = game.Workspace

end

function gunUp()
Tool.GripPos = Vector3.new(0.3,0,-1.2)
end

function gunOut()
Tool.GripPos = Vector3.new(0.3,0,-1.5)
end

function onEquipped()

Tool.Handle.Fire:Stop()

end

function onUnequipped()

Tool.Handle.Fire:Stop()

end

Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)


enabled = true
function onActivated()
if not enabled then
return
end

enabled = false


local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end

local targetPos = humanoid.TargetPoint
local lookAt = (targetPos - character.Head.Position).unit
shootDirect = targetPos

local reload = 1


gunUp()
fire(lookAt, shootDirect)
wait(0.1)
gunOut()
wait(reload)
wait(reload)

enabled = true

end

script.Parent.Activated:connect(onActivated)
Report Abuse
Discern is not online. Discern
Joined: 02 Feb 2013
Total Posts: 331
03 May 2014 08:37 PM
Here. I've modified it. It SHOULD work now.

Tool = script.Parent
VELOCITY = 50 -- constant
loaded=false

colors = {"Really red", "Lime green", "Royal purple"}

function fire(v, shootDirect)


-- find player's head pos

local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)

local head = vCharacter:findFirstChild("Head")
if head == nil then return end

Tool.Handle.Fire:Play()
local launch = head.Position + 10 * v

local missile = Instance.new("Part")

randomcolor = colors[math.random(1, #colors)]

missile.Size = Vector3.new(1,1,4)
missile.Shape = 1
missile.BrickColor = BrickColor.new("" ..randomcolor.. "")
missile.Material = Enum.Material.SmoothPlastic
missile.Locked = true
missile.Transparency = 0.4
missile.TopSurface = 0
missile.BottomSurface = 0

script.Parent.SnowballScript:clone().Parent = missle
missile.CFrame = CFrame.new(launch,shootDirect)
missile.Position = launch
missile.Velocity = v * 60

local force = Instance.new("BodyForce")
force.force = Vector3.new(0,942,0)
force.Parent = missile

missile.SnowballScript.Disabled = false


missile.Parent = game.Workspace

end

function gunUp()
Tool.GripPos = Vector3.new(0.3,0,-1.2)
end

function gunOut()
Tool.GripPos = Vector3.new(0.3,0,-1.5)
end

function onEquipped()

Tool.Handle.Fire:Stop()

end

function onUnequipped()

Tool.Handle.Fire:Stop()

end

Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)


enabled = true
function onActivated()
if not enabled then
return
end

enabled = false


local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end

local targetPos = humanoid.TargetPoint
local lookAt = (targetPos - character.Head.Position).unit
shootDirect = targetPos

local reload = 1


gunUp()
fire(lookAt, shootDirect)
wait(0.1)
gunOut()
wait(reload)
wait(reload)

enabled = true

end

script.Parent.Activated:connect(onActivated)
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
03 May 2014 08:39 PM
'or' works with variables too..

vae = game.Workspace or Workspace

^If game.Workspace is an error, it checks for the Workspace instead of erroring. If Workspace is an error, then the script will error.
Report Abuse
Discern is not online. Discern
Joined: 02 Feb 2013
Total Posts: 331
03 May 2014 08:41 PM
Well it wouldn't work in the case that he's using it.
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