So i have a module for player events but when the player dies the script re runs
local ServerScript = game:GetService("ServerScriptService")
local Module = require(ServerScript.MainModule)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(character)
Module.JoinServer(Player)
Module.SaveData(Player)
character.Humanoid.Died:Connect(function()
Module.Died(Player)
end)
end)
end)
Players.PlayerRemoving:Connect(function(Player)
Module.LeftServer(Player)
end)
Players.PlayerAdded:Connect(function(Player)
local RandomNumber = math.random(35, 60)
while true do
wait(RandomNumber)
Module.SaveData(Player)
print("Random Saving.")
end
end)
Script
function ServerHandler.JoinServer(Player)
print(Player.Name .." Joined server")
Replicated.OtherRemotes.Chat:FireAllClients(Player.Name, "JOINED")
local Leaderstats = Instance.new("Folder",Player)
Leaderstats.Name = "leaderstats"
local data1 = nil
local lowdetail = Instance.new("BoolValue")
lowdetail.Name = "Lowdetail"
lowdetail.Parent = Player
local Worms = Instance.new("IntValue",Leaderstats)
Worms.Name = "Worms"
Worms.Value = WormsDataStore:GetAsync(Player.UserId) or 0
Billoard.Parent = Player.Character
--local Part = Instance.new("Part", Player.Character)
--Part.Anchored = false
--Part.CanCollide = false
--local Weld = Instance.new("WeldConstraint",Part)
--Weld.Part0 = Player.Character.HumanoidRootPart
--Weld.Part1 = Part
if not badgeService:UserHasBadge(Player.UserId, badgeID) then
badgeService:AwardBadge(Player.UserId, badgeID)
end
end
``` the basics of the module