I want to make a scrolling frame, and there's buttons in the scrolling frame. When a player joins, i want the button to clone and the button text is the player's text and when they leave the button gets destroy or disappear. The things is, I can't make it on local script and I need to do it on local script.
Pretty sure that local scripts can still use Players.PlayerAdded so this might work
game.Players.PlayerAdded:Connect(function(player) local newbutton = scrollingframe.Button:Clone() newbutton.Name = player.Name -- using player name here to find button later newbutton.Text = player.Name newbutton.Parent = scrollingframe end) game.Players.PlayerRemoved:Connect(function(player) if scrollingframe:FindFirstChild(player.Name) -- checks if theres a button for the player scrollingframe:FindFIrstChild(player.Name):Destroy() end end)
Just change up the button references cause idk what u use for it
Hope that helped
I don't know if this is what you meant but..
--server script
local addEvent = game.ReplicatedStorage.addEvent local removeEvent = game.ReplicatedStorage.removeEvent
game.Players.PlayerAdded:Connect(function(player) addEvent:FireAllClients(player) end
game.Players.PlayerRemoved:Connect(function(player) removeEvent:FireAllClients(player) end
--local script
local addEvent = game.ReplicatedStorage:WaitForChild("addEvent") local removeEvent = game.ReplicatedStorage:WaitForChild("RemoveEvent")
addEvent.OnClientEvent:Connect(function(player) local buttonClone = button:Clone() buttonClone.Text = player.Name buttonClone.Name = player.Name end
removeEvent.OnClientEvent:Connect(function(player) screenGui:FindFirstChild(player):Destroy() end
Let me know if you have any issues.
--remote eventless method?
local localPlayer = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player) local buttonClone = button:Clone() buttonClone.Parent = localPlayer.PlayerGui.ScreenGui buttonClone.Text = player.Name buttonClone.Name = player.Name end
game.Players.PlayerRemoved:Connect(function(player) localPlayer.PlayerGui.ScreenGui:FindFirstChild(player.Name):Destroy() end