So I was trying to figure out something and wanted to know if this can be even shorter than this:
local Players = game:GetService("Players")
local ValueName
Players.PlayerAdded:Connect(function(Player)
--// VARIABLES
task.wait(1)
local PlayerEmotes = Player:FindFirstChild("PlayerEmotes")
local None = Player:FindFirstChild("PlayerEmotes"):FindFirstChild("None")
local FireHead = Player:FindFirstChild("PlayerEmotes"):FindFirstChild("FireHead")
local EmoteNone = None.Name
local EmoteFireHead = FireHead.Name
--// CURRENT
local CurrentEmote = Player:FindFirstChild("PlayerEmotes"):FindFirstChild("CurrentEmote")
while task.wait(1) do
for index, values in pairs(PlayerEmotes:GetDescendants()) do
if values:IsA("BoolValue") then
if values.Value == true then
ValueName = values.Name
CurrentEmote.Value = tostring(ValueName)
end
end
None:GetPropertyChangedSignal("Value"):Connect(function()
if values:IsA("BoolValue") and values.Name ~= EmoteNone then
values.Value = false
end
end)
FireHead:GetPropertyChangedSignal("Value"):Connect(function()
if values:IsA("BoolValue") and values.Name ~= EmoteFireHead then
values.Value = false
end
end)
end
end
end)
local Players = game:GetService("Players")
local ValueName
Players.PlayerAdded:Connect(function(Player)
--// VARIABLES
task.wait(1)
local PlayerEmotes = Player:FindFirstChild("PlayerEmotes")
local None = PlayerEmotes:FindFirstChild("None")
local FireHead = PlayerEmotes:FindFirstChild("FireHead")
local EmoteNone = None.Name
local EmoteFireHead = FireHead.Name
--// CURRENT
local CurrentEmote = PlayerEmotes:FindFirstChild("CurrentEmote")
while task.wait(1) do
for index, values in pairs(PlayerEmotes:GetDescendants()) do
if values:IsA("BoolValue") and values.Value then
ValueName = values.Name
CurrentEmote.Value = tostring(ValueName)
end
None:GetPropertyChangedSignal("Value"):Connect(function()
if values:IsA("BoolValue") and values.Name ~= EmoteNone then
values.Value = false
end
end)
FireHead:GetPropertyChangedSignal("Value"):Connect(function()
if values:IsA("BoolValue") and values.Name ~= EmoteFireHead then
values.Value = false
end
end)
end
end
end)
None:GetPropertyChangedSignal("Value"):Connect(function()
if values:IsA("BoolValue") and values.Name ~= EmoteNone then
values.Value = false
end
end)
FireHead:GetPropertyChangedSignal("Value"):Connect(function()
if values:IsA("BoolValue") and values.Name ~= EmoteFireHead then
values.Value = false
end
end)
Bare in mind that you’re creating those connections once per second, connections need only be created once, otherwise you’ll end up with a function that’s executed hundreds if not thousands of times each time the event fires.
local Game = game
local Players = Game:GetService("Players")
local function OnPlayerRemoving(Player)
print("Hello world!")
end
while task.wait() do
Players.PlayerRemoving:Connect(OnPlayerRemoving)
end
Run a script like this and check the output window.
Even though I only left the game once the PlayerRemoving connection was made 125 times resulting in ‘Hello world!’ being printed to the console the same number of times.