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.
How do I make a button clones when a player joins through a local script?
2 answers
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
1 comment
I already know how to, and yeah your answer is correct well done.'
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
5 comments
i dont wnt to use remote events
i know how to do that, but i dont know how to do it without remote events. other people can do it.
its not possible without remote events, you can't communicate between clients
i'll edit my post, see if this works.
it is possible. Like I thought instance.new can't be FE through a local script, but there's actually a way to make it FE
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Maybe try with remote events.