Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

does if then works with modulescripts variables ?

my if then wont work if i use a variable from my modulescript but will work perfectly if i use almost everything else, here's an example

In ModuleScript

local module = {
	 ["partDestroyed"] = 0
}

return module

then i made a part in which i added an attachment and a proxmityprompt, the idea is to make the part go transparent when the proximityproimpt is triggered then put it back to normal, i know i can do it all in the same script and without modulescript but this is not the point, i'm trying to figure out how to make a variable usable in multiple scripts at the same time

local prompt = script.Parent
local partDestroyed = require(game.Workspace.Part.Attachment.ProximityPrompt.ModuleScript)

prompt.Triggered:Connect(function(player)
	game.Workspace.Part.Transparency = 1
	partDestroyed.partDestroyed = 1
	print (partDestroyed.partDestroyed)
end)

if partDestroyed.partDestroyed == 1 then
	wait(1)
	game.Workspace.Part.Transparency = 0
	partDestroyed.partDestroyed = 0
end


if the if partDestroyed.partDestroyed == 1 is replaced to if 2 == 2 it works, but as it is, it's like the if then is never triggered, some thoughts ?

1 answer

pretty certain you can only do:

local module = {}

module.partDestroyed = 0

return module

then

local prompt = script.Parent
local partDestroyed = require(game.Workspace.Part.Attachment.ProximityPrompt.ModuleScript)

prompt.Triggered:Connect(function(player) game.Workspace.Part.Transparency = 1 partDestroyed.partDestroyed = 1 print (partDestroyed.partDestroyed) end)

if partDestroyed.partDestroyed == 1 then wait(1) game.Workspace.Part.Transparency = 0 partDestroyed.partDestroyed = 0 end

it might also be that the module script has to be in somewhere like replicatedstorage.

This discussion is preserved as it was. New answers, comments, and votes are closed.