In studio, when I go to join my game, the module scripts inside of the game work perfectly fine, only if you don’t respawn. When you respawn, everything stops working and I am very confused on why they stop working.
Im thinking it might be the script that im loading my modules in? I have no idea. Im still learning lua, so ofcourse i will make little mistakes here and there.
Put it inside StarterCharacter instead of StarterPlayer or you will need to run a function on Player.CharacterAdded, this gets fired when the player respawns, because well when the original character dies you should replace it with the new one.
This unfortunately did not work. I even tried editing the function inside of my module script (the function that gets the character) and replaced it with a module.Character = player.Character or player.CharacterAdded:Wait() because it was originally module.Character = player.Character and that still did not work.
local module = {}
local enabled = false
module.Player = game:GetService("Players").LocalPlayer
local function onTouch(object)
if object:IsA("Part") and object.Name == 'Part' then
object.BrickColor = BrickColor.Random()
end
end
local function onCharacterAdded()
module.Character = module.Player.Character
module.Humanoid = module.Character:WaitForChild("Humanoid")
if enabled then
module.Humanoid.Touched:Connect(onTouch)
end
end
if module.Player.Character then onCharacterAdded(module.Player.Character) end
module.Player.CharacterAdded:Connect(onCharacterAdded)
function module.Touch()
enabled = true
if module.Humanoid then
module.Humanoid.Touched:Connect(onTouch)
end
end
return module