You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I need it so that when a player joins the game, a UI clones and parents it to the player.
What is the issue? Include screenshots / videos if possible!
The current script doesn’t work. (script in comments)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
My current script which doesn’t work.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
The game is a 2d UI based game. Players spawn in and get a frame. They control that UI with UserInputService. The game works fine single player, just I would like multi-player compatibility. Add me on discord if you would like more info for help. (official_ae#2606) or leave a comment.
game.Players.PlayerAdded:Connect(function(plr)
local mainUi = game.ReplicatedStorage:WaitForChild("MainUI")
local cloned = mainUi:Clone()
cloned.Parent = plr.PlayerGui
end)
Current Controlling script;
local UIS = game:GetService("UserInputService")
local World = script.Parent
World.IgnoreGuiInset = true
World.Parent = game.Players.LocalPlayer.PlayerGui
local Player = World.Player
while wait() do
if UIS:IsKeyDown(Enum.KeyCode.D) then
Player.Position = UDim2.new(Player.Position.X.Scale + 0.01,Player.Position.Y.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale)
end
if UIS:IsKeyDown(Enum.KeyCode.A) then
Player.Position = UDim2.new(Player.Position.X.Scale - 0.01,Player.Position.Y.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale)
end
if UIS:IsKeyDown(Enum.KeyCode.W) then
Player.Position = UDim2.new(Player.Position.X.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale - 0.02,Player.Position.Y.Scale)
end
if UIS:IsKeyDown(Enum.KeyCode.S) then
Player.Position = UDim2.new(Player.Position.X.Scale,Player.Position.Y.Scale,Player.Position.Y.Scale + 0.02,Player.Position.Y.Scale)
end
end
Are there ScreenGui’s with your frames within the startergui? U don’t have to clone them in a script and parent them there. Startergui puts them in every players GUI when they join/respawn.
U have the MainUi in the replicated storage, Why not put it in the startergui. U can have a local script determine when to show it or not. Putting it in the startergui would fix it to go to everyone. Also if you want to keep it the same try adding the MainUi to the player like you do when a when player is added to the game function so then it will parent it to the player when they join. Now on respawn go into the MainUi properties and make sure it does not reset on death or respawn.
I don’t understand + I want to clone it everytime someone joins and delete it when they leave, it’s for multiplayer experiences and what you said doesnt work + i dont understand it
game.Players.PlayerAdded:Connect(function(player)
-- Adds the gui to the player on player added
local mainUi = game.ReplicatedStorage:FindFirstChild("MainUI")-- If script can find MainUI in replicated storage then it sets mainui as MainUI
local cloned = mainUi:Clone()
cloned.Parent = player.Character.PlayerGui-- Clones it just to the player that joined the game
end)
-- Idk why u want to delete it from the player when they leave because when they leave it already gets destroyed but
game.Player.PlayerRemoving:Connect(function(player)
-- Remove it from the player here though may cause error because player is not in server anymore
if player.Character.PlayerGui:FindFirstChild("MainUI") then-- If the script can find GUI on player then
player.Character.PlayerGui.MainUI:Destroy()-- Removes the GUI on removal for just the player that removed
end
end)
Does that help? Though your making a 2d game. if that gui is always enabled then I would put the mainUI in the starter GUI and set the mainUI as enabled so then when any player join its already on there screen, then u don’t have to go through the process of cloning it to every player.
Also:
Make sure this code is within a script within the serverscriptservice. wont work on local script
So the GUI is set just to show yourself not every player in the server U don’t wanna use on player added events to show all player you’ll wanna get every player in game and show there position on the frame
im only using it for testing and the game isn’t public, i will make my own version of it when its done, for now it works and thanks for it, but i will remove it as soon its ready for public testing