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
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | local newbutton = scrollingframe.Button:Clone() |
03 | newbutton.Name = player.Name -- using player name here to find button later |
04 | newbutton.Text = player.Name |
05 | newbutton.Parent = scrollingframe |
06 | end ) |
07 |
08 | game.Players.PlayerRemoved:Connect( function (player) |
09 | if scrollingframe:FindFirstChild(player.Name) -- checks if theres a button for the player |
10 | scrollingframe:FindFIrstChild(player.Name):Destroy() |
11 | end |
12 | 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