#Module Script Problems

49 messages · Page 1 of 1 (latest)

noble parcel
#
UserInputService.InputBegan:Connect(function(input, processed)
    if input.KeyCode == Enum.KeyCode.B then
        BuildingMode = true

        --// Calling Module Functions

        PlacementHologramModule:HologramPartCreation()
        PlacementHologramModule:HologramPositionMovement(Mouse, BuildingMode)
        task.spawn(function()
            PlacementHologramModule:HologramOrientationMovement(BuildingMode)
        end)
        UserInputService.InputBegan:Connect(function(input, processed)
            if input.UserInputType == Enum.UserInputType.MouseButton1 then
                PlacementHologramModule:HologramPartDestroying()
                BuildingMode = false
            end
        end)
    end
end)

The BuildingMode function only comes up as false within the Module Script before B is pressed, after that it is always set to true for som reason. If you also see any other optimizations possible in my code, let me know as I am quite new.

noble parcel
#

hi sorry for the ping, so im passing "BuildingMode" as a param to my module script
in this script (not the module), the BuildingMode variable changes as it should (when MouseButton1 is clicked, as seen by the UIS)
however, the BuildingMode variable that is being passed to the module script is not being changed and is set to true after the player has pressed B and doesn't change even when the value of it inside this script changes

#

sorry if that doesn't make sense, if you tell me what part you dont understand i can clear it up for you

shy hound
#

the module script cant change variables on another scriñt

#

script*

#

the parameter acts as a new value

#

look into using return

noble parcel
noble parcel
#

i had some debugging prints inside and when

        UserInputService.InputBegan:Connect(function(input, processed)
            if input.UserInputType == Enum.UserInputType.MouseButton1 then
                PlacementHologramModule:HologramPartDestroying()
                BuildingMode = false
            end
        end)

this made the BuildingMode false, there was a print before the if BuildingMode and it printed true after the B key was pressed

#

sorry i should send as message

#
function PlacementHologramModule:HologramPositionMovement(Mouse, BuildingMode)
    if BuildingMode then
        Mouse.Move:Connect(function()
            Mouse.TargetFilter = HologramPart
            local Success, Error = pcall(function()
                if Mouse.Target == "Baseplate" or Mouse.Target.Name == "Baseplate" then
                    HologramPart.Parent = game.Workspace
                    local HologramPartPosititonX = math.floor(Mouse.Hit.X)
                    local HologramPartPosititonY = Mouse.Hit.Y + 1
                    local HologramPartPosititonZ = math.floor(Mouse.Hit.Z)
                    local HologramPartPosition = Vector3.new(HologramPartPosititonX, HologramPartPosititonY, HologramPartPosititonZ)
                        
                    --// Tweening Position Change
                        
                    local HologramPartPositionTween = TweenService:Create(HologramPart, HologramPartTweenInfo, {Position = HologramPartPosition})
                    HologramPartPositionTween:Play()
                end
            end)
        end)
    end
end
noble parcel
# shy hound can we see the module script?

i'm not sure if it is because the BuildingMode = false is after the param is instantiated inside the module script, that could be a starting point but i'm not very familiar with module scripts

shy hound
#

youre always setting it to true

#

before running the function

#

if you change the variable in the script it wont change in the module script

#

because the module script parameter acts as a new variable

noble parcel
#

ohh, is there any way to get around that?

shy hound
#

like any other parameter

shy hound
#

/true

#

and call it when you change the variable

noble parcel
#

alright thanks man👍

noble parcel
shy hound
noble parcel
# shy hound ye

sorry for the ping but would you know where I can find information on things like dot syntax and colons, init, self and that module stuff because when I look on docs i can't seem to find that stuff

shy hound
# noble parcel sorry for the ping but would you know where I can find information on things lik...

The . (dot) operator in Lua is used to invoke the method of an object, and it is a widely used operator in Lua. The :(colon) operator in Lua is used when you want to pass an invisible parameter to the method of an object that you are calling.
Self is the object that the method was called on:

apple:Epic()

function apple:Epic()
  --here, self is the "thing" the method was called on, hence apple.
end

--This is the same as

apple.Epic(apple)

function apple.Epic(self)
  --here, we pass the self as a parameter, hence apple.
end

https://create.roblox.com/docs/reference/engine/classes/ModuleScript

A type of script object that runs once when require is called with it.
Returns exactly one value, usually a table of functions, to used by other
scripts. Useful for compartmentalizing code.

#

heres some

noble parcel
#

am i blind though or is there like nothing on docs about the other stuff like Init and that stuff in docs?

#

or is it just the same as external languages so I can learn it from anywhere?

shy hound
#

but hu

#

uh*

#

you'll probably find it on the lua docs instead

#

since it isnt luau or roblox-specific

noble parcel
shy hound
#

its just a variable name probably

noble parcel
#

nvm i found a devforum on it, don't worry

shy hound
#

the only thing that it reminds me of is table.find(haystack, needle, init)

#

where it starts a

#

oh ok

noble parcel
#

thanks a ton man

shy hound
#

nice

#

np