I was trying to test myself and tryed to make text button, after clicking on it it spawns another text button. But new buttons are adding to Starter GUI folder, so i need to respawn to see them. I found out that i need to put new Buttons in Player Gui, i tryed to do something but it doesnt work
This code after i tryed to fix it:
local button1 = script.Parent local function onButtonActivated(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local part1 = Instance.new("TextButton") part1.Parent = player.PlayerGui part1.Name = "vlad" part1.Position = UDim2.new(math.random(), math.random(), math.random()) part1.Size = UDim2.new(0,100, 0,100) while true do button1.BackgroundColor3 = Color3.new(255, 0, 0) wait(0.2) button1.BackgroundColor3 = Color3.new(255, 255, 255) wait() end end button1.Activated:Connect(onButtonActivated)
and this is working script but need to respawn to see new buttons:
local button1 = script.Parent local function onButtonActivated() local part1 = Instance.new("TextButton", game.StarterGui.ScreenGui) part1.Name = "vlad" part1.Position = UDim2.new(math.random(), math.random(), math.random()) part1.Size = UDim2.new(0,100, 0,100) part1.TextScaled = true while true do -- its for main button and works good button1.BackgroundColor3 = Color3.new(255, 0, 0) wait(0.2) button1.BackgroundColor3 = Color3.new(255, 255, 255) wait() end end button1.Activated:Connect(onButtonActivated)
EDIT: Players.Licmor.PlayerGui.ScreenGui.TextButton.LocalScript:5: attempt to index local 'player' (a nil value) I get this error every time and it seems like game.Players:GetPlayerFromCharacter is not working
You are placing the textbutton inside the PlayerGui, it needs to be inside of a ScreenGui for it to appear.