i had a script that would insert a TextLabel into my screen gui but it doesnt work heres my script: and in the output it was saying "LevelGui is not a valid member of StarterGui"
script.Parent.Touched:connect(function(hit) if hit ~= nil then local char = hit.Parent if char ~= nil then local humanoid = char:FindFirstChild("Humanoid") if humanoid ~= nil then game.StarterGui.LevelGUI = Instance.new ("TextLabel") end end end end)
and "LevelGui" is a ScreenGui that i added in the StarterGui
Here are the problems with the script above.
connect
is deprecated. Use Connect
instead. This isn't causing your script to break, but it is good to know, since deprecated methods are no longer supported by roblox.
You wouldn't change the starter gui, as that is what is replicated to the player, not what they see. You would have to go to the player gui.
This would require remote events since a script cannot access the playergui. Otherwise, this will work in studio, but not in game.
The error message occurred because of the equals sign. It thinks that LevelGui is a property of the StarterGui, but it isn't. If you are trying to insert a textlabel, then you would parent the new instance to the LevelGui.
Here is the solution to all four problems.
Put a RemoteEvent called MakeTextLabel inside the ReplicatedStorage
LocalScript inside the gui called LevelGUI
local replicated = game:GetService("ReplicatedStorage") local createtext = replicated:WaitForChild("MakeTextLabel") createtext.OnClientEvent:Connect(function() local textlabel = Instance.new("TextLabel") -- modify/customize the text label textlabel.Parent = script.Parent -- if you want to delete it after, put the code here, otherwise leave blank. end)
Script inside part.
local replicated = game:GetService("ReplicatedStorage") local createtext = replicated:WaitForChild("MakeTextLabel") script.Parent.Touched:Connect(function(hit) local player = nil for i,v in pairs(game.Players:GetPlayers())do if v and v.Character and v.Character:IsAncestorOf(hit) then player = v break end end if player == nil then return end createtext:FireClient(player) end)