[SOLVED] My script is not working, help!

Hello i’m trying to make an light that spins but it’s not working, it’s an module script in ReplicatedStorage

local module = {}

local RunService = game:GetService("RunService")
function module.Init()
	local Lighthouse = workspace:FindFirstChild("LighthouseLight")
	Lighthouse.PrimaryPart = Lighthouse.Center
	RunService.Heartbeat:Connect(function()
		Lighthouse:SetPrimaryPartCFrame(Lighthouse.PrimaryPart.CFrame * CFrame.Angles(0, 0.5 * 0))
	end)
end

return module

Try this:

Lighthouse:SetPrimaryPartCFrame(Lighthouse.PrimaryPart.CFrame * CFrame.Angles(0, 0.5, 0))

Still not working sadly, the light part does not spin

Is there an error in the output?

No errors in output, it simply don’t spin i don’t know why

Could you show us the script where you call the module?

image

No, the script where you run require(<module path>) and you call module.Init()

I don’t call it, i just put this code in the ModuleScript, how i will call it ? put a script in the part?

Yes. You could put a script in your part, or in ServerScriptService. It’s up to you. The main thing is to require the module and call the Init function. Here’s a link to a documentation about modules.
https://education.roblox.com/resources/intro-to-module-scripts

So i placed an script in ServerScriptService with that code:
require(game.ReplicatedStorage.Game.Lighthouse) is that right

Even with require code is not working what can i do?

Hey, sorry for this late reply. The require code returns the module functions, so call the module.Init function

I think you need to put the script after module and before return in the braces “{}” so the module works

edit: im not a pro at modules but it’s what I know

My code to call the function is not working:

game.Players.PlayerAdded:Connect(function(player)
	require(game.ReplicatedStorage.Game.Lighthouse).module.Init()
end)

and this is the error:

image

Require the module and call the function…

Only do .Init()
If memory serves right that is

Like that?

local lighthouseModule = require(game.ReplicatedStorage.Game.Lighthouse)

game.Players.PlayerAdded:Connect(function(player)

lighthouseModule.Init()

end)

But there is also module.Init() on the ModuleScript, this is the ServerScript to call the module

Yeah i guess, im not sure tho i dont remember correctly…
I checked wiki and its correct

1 Like

It worked! i just need to add an delay because it’s tho fast can i do

RunService.Heartbeat:Connect(function()
wait(0.7)

?