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

Why does this script not work in the actual game bu it does in studio?

It works in studio but not the real game. By the way, this is a module script.

local BloodEnabled = false

local parent = script.Parent

local function on()
BloodEnabled = true

end

local function off()
BloodEnabled = false

end

local function OnClicked()
if BloodEnabled == true then off() else on() end

end
parent.MouseButton1Click:connect(OnClicked)

Can someone guide me?

Thanks.

2 comments

0

why would this be in a module script

0

because of my broadness

1 answer

✓ Accepted answer

###ModuleScripts don't run unless you require that module. However, for GUI event listening, you should keep that in LocalScripts. I did tell you in the past to use modules for global variables, sorry for being broad. Also, you do not need separate functions to toggle a boolean, simply use the not keyword and it reverses a boolean.

-- ModuleScript, preferably under your LocalScript
local module = {}
module.BloodEnabled = false

function module:ToggleBlood() 
    -- self is a reference to the module table
    self.BloodEnabled = not self.BloodEnabled
    -- setting BloodEnabled 
end

return module -- return the table 

###From your local script:

local modulescript = require(script.BloodModule) 
-- in order to get the table and everything in it we must require it

local function OnClicked()
    modulescript:ToggleBlood()
end
parent.MouseButton1Click:Connect(OnClicked)
-- connect is deprecated use Connect

1 comment

0

Oh okay thank you.

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