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

How are parameters passed in module scripts?

Asked by 5 years ago

This question has been solved by the original poster.

Module Script -- Game.ServerScriptService.Modules.MonsterDrop

local module = {}
function module:onEnemyDead(enemy)
    local tag = enemy:FindFirstChild("Attacker")
    if tag ~= nil then
        if tag.Value ~= nil then
            local leaderStatsMoney = tag.Value:FindFirstChild("Money")
            local leaderStatsExp = tag.Value:FindFirstChild("Money")
            if leaderStatsMoney ~= nil then
                leaderStatsMoney.Value = leaderStatsMoney.Value + (math.random(1,5)*game.Workspace.EventBoost.Value)
                wait(0.1)
                script:Destroy()
            end
            if leaderStatsExp ~= nil then
                leaderStatsExp.Value = leaderStatsExp.Value + (math.random(10,15)*game.Workspace.EventBoost.Value)
                wait(0.1)
                script:Destroy()
            end
        end
    end
    print(enemy)
end
return module

Server Script -- Workspace.FindFirstChild("Bandit.Exp/Gold Script")

local enemy = script.Parent.Monster
local DropModule = require(game.ServerScriptService.Modules.MonsterDrop)

function Die() 
    DropModule.onEnemyDead(enemy)
end

enemy.Died:Connect(Die)

Errors: ServerScriptService.Modules.MonsterDrop:3: attempt to index local 'enemy' (a nil value)

Questions: -How would I pass monster parameters and what is a good way of doing it -How would I use collection service in an rpg game that I'm trying to make (Optimized and clean) -How does object oriented work in module scripts, and where are good places to put the module scripts? -Is there any complete guide to using module script? I tried finding on google but I can't seem to find a complete guide

3
Line 5, use a colon : and not a period . User#19524 175 — 5y
0
Oooh sorry clumsy mistake xD xxXTimeXxx 101 — 5y
0
Where would I find a complete tutorial for module scripts and object oriented and how could I efficiently apply it to my RPG game? :O xxXTimeXxx 101 — 5y
2
https://www.lua.org/pil/16.html here's a dandy resource Goulstem 8144 — 5y
1
Don't get confuse with parameters & argument, parameters are technically variables, while arguments are the value, so In reality you're passing an argument, The parameter sets the argument as its value. Next_Byte 21 — 5y

Answer this question