#velocity/While loop issues

1 messages · Page 1 of 1 (latest)

hollow nova
#

Heyo, having a slight issue where this while loop is not running though the process. I was hoping I could get someone more experenced than myself to give it a quick once over and give me some advice as to the issue as this has been stumpping me for a few hours now. Thanks in advance!!

''''' lau
local Gamba = math.random(1, 255)
local MiniGamba = math.random(1, 35)

local function SunSpawns()
while mmTouching() == true do
task.wait(.045)
local clone = game.ServerStorage.SunSpots:Clone()
clone.Name = "SunSpots"
SunSpots.Anchored = false
SunSpots.Shape = "Ball"
SunSpots.Material = math.random(1, 45)
SunSpots.Position = script.Parent.Position("Sun Spawner")
SunSpots.Size = Vector3.new (MiniGamba, MiniGamba, MiniGamba)
SunSpots.BrickColor = BrickColor.new(Gamba, Gamba, Gamba)
SunSpots.AssemblyLinearVelocity = Vector3.new(Gamba, Gamba, Gamba)
SunSpots.Parent = game.Workspace
task.spawn(function()
while mmTouching do
print ("Spawn loop N-word")
task.wait(5)
game.Debris:AddItem(SunSpots, 10)
end
end)
end
end
''''

analog yarrow
#

what does mmTouching() return

#

and it doesnt work because mmTouching() is something else other than true

hollow nova
#

mmTouching is a script I have on a platform so when I stand on it then it sets it to a true value

#

I was trying to had a spot to stand then it activates it but this is my first time using multiple scripts speaking to each other

analog yarrow
#

so mmTouching is a script

hollow nova
#

yea do you want the code for that one too?

analog yarrow
#

what kind of script is mmTouching

hollow nova
#

its just script, I attached it to a part

analog yarrow
#

well to put it in simple terms

#

you cannot add scripts as variables

#

such as

#
local scriptVar=workspace.Script
#

you can only do that with modulescripts

#

such as

#
local moduleScript=require(game.ReplicatedStorage.ModuleScript)```
hollow nova
#

I think I get what you mean, so the script thats supposed to set it as true is not actully sending over the true statement?

open kelpBOT
#

studio** You are now Level 2! **studio

hollow nova
#

so its not working because its perm set as false?

analog yarrow
#

why is there parenthesis in mmTouching()

#

like are you calling a function?

hollow nova
#

I was trying to, My goal was to run the while loop as a function so that as long as a stood on the platform a bunch of balls would spawn in different sizes, colors and so on

#

This is like my third project so forgive me if thats not what you meant lol

analog yarrow
#

so mmTouching() is a function and mmTouching is a script

hollow nova
#

Ive been using it as the placeholder name for a script because thats its sole purpose but its mainly for the function

analog yarrow
#

if you do something like ```lua
while false==true do
end

analog yarrow
hollow nova
#

its a function for the while loop thats all

analog yarrow
#

show the function then

hollow nova
#

yea this is the other part of the function ive been using

script.Parent.Touched:Connect(function(plr)
local Player = game.Players:GetPlayerFromCharacter(plr.Parent)
local mmTouching = false
local debounce = false

if Player then
    debounce = true
    mmTouching = true
    task.wait(.50)
    print ("looping")
    mmTouching = false
    debounce = false
end

end)

analog yarrow
#

is the sunSpawns function like just by itself

#

first of all if mmTouching is a boolean there should be no parenthesis

hollow nova
#

ah okay

analog yarrow
#

unless you just do something like

local function mmTouching()
  return true
end
local mmTouching=mmTouching()```
#

and mmTouching doesn't work outside of the function that it is in

hollow nova
#

ohh okay

analog yarrow
#

personally i would do

hollow nova
#

so what should I do to get them to speak to eachother?

analog yarrow
#
local Gamba = math.random(1, 255)
local MiniGamba = math.random(1, 35)

local function SunSpawns()
    while true do
      if mmTouching==true then
        task.wait(.045)
        local clone = game.ServerStorage.SunSpots:Clone()
        clone.Name = "SunSpots"
        SunSpots.Anchored = false
        SunSpots.Shape = "Ball"
        SunSpots.Material = math.random(1, 45)
        SunSpots.Position = script.Parent.Position("Sun Spawner")
        SunSpots.Size = Vector3.new (MiniGamba, MiniGamba, MiniGamba)
        SunSpots.BrickColor = BrickColor.new(Gamba, Gamba, Gamba)
        SunSpots.AssemblyLinearVelocity = Vector3.new(Gamba, Gamba, Gamba)
        SunSpots.Parent = game.Workspace
        task.spawn(function()
            while mmTouching do
                print ("Spawn loop N-word")
                task.wait(5)
                game.Debris:AddItem(SunSpots, 10)
                end
        end)
        end
    end
end```
#

this is different because the while loop still runs

#

and it checks if mmTouching is true, so if it is true then it will run

#

if it is not true then it will just stop

hollow nova
#

oh sweet okay

analog yarrow
#

wait i don't think that works let me change it rq

hollow nova
#

then for sending the signal for swapping between true and false will my other script work okay or do I need to modify it

analog yarrow
#

ok now its more beginner friendly

hollow nova
#

legendddd tyty

analog yarrow
#

;compile

local debounce=false
task.spawn(function()
  while task.wait() do
    if debounce~=false then return end
print("hi")
end
end)
task.wait(3)
debounce=true
timber fossilBOT
#
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:2: attempt to index a nil value (global 'task')
stack traceback:
prog.lua:2: in main chunk
[C]: in ?

analog yarrow
#

i forgot how to use compiler

hollow nova
#

okay I think I got it