Why does my local script not Repeat on respawn

I have been Banging my head on a wall trying to figure out why This local script is not repeating when the player dies.

First I should say, this is a custom HotBar Gui. Yes, the script Does work. It just stops working when the player dies or resets.

After a week of testing to PinPoint the Bug, I have Concluded that something inside of-

function hotbarKey(Slot)

-is Causing this bug.

(Video)

(Server Script)

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		RemoteEvent:FireClient(plr)
	end)
end)

(Local Script)

local plr = game.Players.LocalPlayer
local RemoteEvent = game.ReplicatedStorage.Folder.RemoteEvent
local RemoteEvent2 = game.ReplicatedStorage.Folder.RemoteEvent2

local StrNum = {["One"] = "1", ["Two"] = "2", ["Three"] = "3", ["Four"] = "4", ["Five"] = "5", ["Six"] = "6", ["Seven"] = "7", ["Eight"] = "8", ["Nine"] = "9"}
local tools = {}

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local SelectedSlot = 0

function hotbarKey(Slot)
	print(Slot)
	for i, v in pairs(MainFrame:GetChildren()) do if v.ClassName == "ImageButton" then v.SlotName.TextColor3 = Color3.fromRGB(255,255,255) v.BackgroundColor3 = Color3.fromRGB(104, 104, 104)end end --v.ToolName.TextColor3 = Color3.fromRGB(255, 255, 255)
	for i, v in pairs(plr.Character:GetChildren()) do if v:IsA("Tool") then v.Parent = plr.Backpack end end
	for i, v in pairs(tools) do
		if not v:FindFirstChild("SlotName") then return end
		if v.SlotName.Value == Slot.Name then
			v.Parent = plr.Character
			--print(plr)
		end
	end
	SelectedSlot = tonumber(Slot.SlotName.Text)
	Slot.SlotName.TextColor3 = Color3.fromRGB(0, 170, 255)
	Slot.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
	--Slot.ToolName.TextColor3 = Color3.fromRGB(46, 46, 46)
end

Where is the localscript located?

The Local Script is located in Starter Gui.

Reset On Spawn is activated? [30 chars]

image

Its on screen gui instances tho.

Yes, if this is what you are talking about.

Try disabling it and then testing.

Yes, the Guis do Stay, but the local script is not work properly

Not really sure what is causing this…

[SOLUTION]

Finally I have Figured it out. The problem Had something to do with the way I fired the Remote Event from the server. For some reason local scripts don’t like remote events replicating from the server, after the player respawns.

The way I fixed this problem was, removing the Remote Event entirely.

1 Like