I have a module script that has a function, and to use it, you need to add the character and effect to add.
local cd = script.Parent.ClickDetector
local effectMgr = require(game.ReplicatedStorage.EffectManager)
cd.MouseClick:Connect(function(plr)
local char = plr.Character
effectMgr.AddEffect(char, Bleeding)
end)
The test script ^
local effectFolder = "Effects"
local effectPreset = "Preset"
local effectEvnt = game.ReplicatedStorage.Effect
function module.AddEffect(character,effect)
local effectsFold = character:WaitForChild(effectFolder)
effectsFold:FindFirstChild(effect).Value = true
end
function module.RemoveEffect(character,effect)
local effectsFold = character:WaitForChild(effectFolder)
effectsFold:FindFirstChild(effect).Value = false
end
function module.PresetAdd(character,presetEffect)
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
preseteffectsFold:FindFirstChild(presetEffect).Value = true
end
function module.PresetRemove(character,presetEffect)
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
preseteffectsFold:FindFirstChild(presetEffect).Value = false
end
the module script ^
I want to know how to make a sorta like, dropdown menu for all the possible effects (user-made effects too).
I don’t think that’s how I want it to work, or I probably don’t understand it.
I want the user to be able to specify one of the effects in a different script, but I think the function parameters return the entire type.
local module = {}
--[THIS MODULE IS ONLY COMPATIBLE WITH EFFECT SCRIPTS THAT USE .CHANGED EVENTS TO MONTOR ENABLING/DISABLING EFFECTS.]--
-- The effect name must be exactly the same.
local effectFolder = "Effects"
local effectPreset = "Preset"
local effectEvnt = game.ReplicatedStorage.Effect
type effct = "Bleeding" | "Burning" | "Freeze" | "Poison"
function module.AddEffect(character,effect: effct)
local effectsFold = character:WaitForChild(effectFolder)
effectsFold:FindFirstChild(effect).Value = true
end
function module.RemoveEffect(character,effect)
local effectsFold = character:WaitForChild(effectFolder)
effectsFold:FindFirstChild(effect).Value = false
end
function module.PresetAdd(character,presetEffect)
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
preseteffectsFold:FindFirstChild(presetEffect).Value = true
end
function module.PresetRemove(character,presetEffect)
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
preseteffectsFold:FindFirstChild(presetEffect).Value = false
end
return module
test script:
local cd = script.Parent.ClickDetector
local effectMgr = require(game.ReplicatedStorage.EffectManager)
cd.MouseClick:Connect(function(plr)
local char = plr.Character
effectMgr.AddEffect(char, "Bleeding")
end)
I get this error once clicking the part:
ReplicatedStorage.EffectManager:14: attempt to index nil with ‘Value’
Does the instances the EffectManager try to access exist?
does effectsFold.Bleeding exist?
if not then change it to this
local module = {}
--[THIS MODULE IS ONLY COMPATIBLE WITH EFFECT SCRIPTS THAT USE .CHANGED EVENTS TO MONTOR ENABLING/DISABLING EFFECTS.]--
-- The effect name must be exactly the same.
local effectFolder = "Effects"
local effectPreset = "Preset"
local effectEvnt = game.ReplicatedStorage.Effect
local Effect = { -- table so then user generated effects can be added too
"Bleeding",
"Burning",
"Freeze",
"Poison"
}
function module.Init()
local effectsFold = character:WaitForChild(effectFolder)
for i,v in Effect do
local boolValue = Instance.new("BoolValue")
boolValue.Parent = effectsFold
boolValue.Name = v
end
end
function module.AddEffect(character,effect:)
local effectsFold = character:WaitForChild(effectFolder)
effectsFold:FindFirstChild(effect).Value = true
end
function module.RemoveEffect(character,effect)
local effectsFold = character:WaitForChild(effectFolder)
effectsFold:FindFirstChild(effect).Value = false
end
function module.PresetAdd(character,presetEffect)
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
preseteffectsFold:FindFirstChild(presetEffect).Value = true
end
function module.PresetRemove(character,presetEffect)
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
preseteffectsFold:FindFirstChild(presetEffect).Value = false
end
return module
local module = {}
--[THIS MODULE IS ONLY COMPATIBLE WITH EFFECT SCRIPTS THAT USE .CHANGED EVENTS TO MONTOR ENABLING/DISABLING EFFECTS.]--
-- The effect name must be exactly the same.
local effectFolder = "Effects"
local effectPreset = "Preset"
local effectEvnt = game.ReplicatedStorage.Effect
local Effect = { -- table so then user generated effects can be added too
"Bleeding",
"Burning",
"Freeze",
"Poison"
}
local effectsFold = character:WaitForChild(effectFolder)
function module.AddEffect(character,effect)
effectsFold:WaitForChild(effect).Value = true
end
function module.RemoveEffect(character,effect)
effectsFold:WaitForChild(effect).Value = false
end
local preseteffectsFold = character:WaitForChild(effectFolder:WaitForChild(effectPreset))
function module.PresetAdd(character,presetEffect)
preseteffectsFold:WaitForChild(presetEffect).Value = true
end
function module.PresetRemove(character,presetEffect)
preseteffectsFold:WaitForChild(presetEffect).Value = false
end
return module
ReplicatedStorage.EffectManager:14: attempt to index nil with ‘Value’
means that effectsFold:FindFirstChild(effect) is returning nil, which is only if the item doesn’t exist, so possibly do a WaitForChild?