GUI from replicated storage wont work when put into starter gui

Hey guys, I’m having a really hard time figuring out why this wont work. I have a GUI in replicated storage and every time I bring out the clone of it game.ReplicatedStorage.GUI:Clone() - For example, it doesnt work when I put it in starterplayer. I dont want it in playergui because then it shows up on everyones screen.

If anyone knows why this might be happening, any help would be appreciated. (and yes I do set it to visible)

I’ve done this process through both a local script, and a serverscript from a remoteevent.

thanks.

1 Like

The contents of StarterGui get replicated into the PlayerGui when the character spawns (unless ResetOnSpawn is off).

If you manually put something in StarterGui, the player won’t get it. It needs to go in their PlayerGui.

2 Likes

If you are using a local script to clone the UI it and put it in PlayerGUI it should not be visible to everyone

Example of code inside the StarterPlayerScript:

repeat wait(0.1) until game:IsLoaded()

local rs = game:GetService("ReplicatedStorage")
local clonedUI = rs.GUI:Clone()
clonedUI.Parent = game.Players.LocalPlayer.PlayerGui
2 Likes

@batteryday @Stephenesta_aqui

I did go originally go through playerGUI, but when I go through the process of activating it, both player1 and 2 get a GUI pop up.

Gyazo link to video example

script in question causing the strange stuff :confused:

  • In a local script in starterplayerscripts
local debounce = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local hit = game.Workspace.hit
local playertransfer = ReplicatedStorage.PlayerWhoHit

game.Workspace.hit.Touched:Connect(function(hits)
	if debounce == false then
		if hits.Parent:FindFirstChild("Humanoid") then
			debounce = true
			local GUI =  ReplicatedStorage.DeliveryGUI.DeliveryAccept:Clone()
			GUI.Parent = player.PlayerGui
			print("delivery")
			playertransfer:FireServer(hits.Parent)
			wait(3)
			debounce = false

		end

	end
end)


1 Like

What do you want to happen? Do you want a text label to pop up when hit or what? You also aren’t specifying a part, you are saying is the workspace gets touched, which is not a thing.

Check the link I sent, shows what happens when you hit the brick.

It’s a delivery system and only the person who touched the brick should get the popup, but everyone gets it for some reason

it’s workspace.hit (the brickname)

1 Like

Ok, so you are having this fire to another player?

1 Like

hit the block → gui shows up on the person who hit it’s screen ONLY → rest of functions

I see the issue you are firing the event to make it visible to all the players please show me what the event does when it’s fired, and I can help you fix it

Also you do not need to clone it everytime, you just need to have it become visible when it gets hit

	print("here")
	script.Parent.Touched:Connect(function(hit)
		if debounce == false then
			local player = game:GetService("Players"):GetPlayerFromCharacter(OGplayer)
			if player then
				if hit.Parent:FindFirstChild("Humanoid") then
					debounce = true

					local leaderstats =  player.leaderstats.Money
					leaderstats.Value += 1500
					wait(3)
					debounce = false
					script:Destroy()
					
				end
			end
		end
	end)

end)

This is the remote event script you are talking about, it’s just to deal with leaderstats. This script just gets inserted into an object later on.

Ok, lots of issues with this. Touched Events can only be fired by Scripts not LocalScripts, so a way to fix this is by doing this:

In a script where the part is the parent of what you want to be hit do this:

part.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if debounce == false then
		debounce = true
		print("delivery")
		local GUI = rs.DeliveryGui.DeliveryAccept:Clone()
		GUI.Parent = player.PlayerGui
		task.wait(3)
		debounce = false
	end
end)

Then inside of a LocalScript do this:

local rs = game:GetService("ReplicatedStorage")
local playerTranfer = rs.PlayerWhoHit
local yesBtn = "Put Button Here" -- Change to your button

yesBtn.MouseButton1Click:Connect(function()
	playerTranfer:FireServer()
end)

However there are issues with cloning the UI, because then you’ll need a way to destroy it. My recommendation would be to put the UI inside of StarterGui, so you can just make it visible and invisible with the script. If you would like to do that change your code to this:

Script:

local debounce = false
local part = game.Workspace.hit


part.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if debounce == false then
		debounce = true
		print("delivery")
		player.PlayerGui.DeliveryGui.DeliveryAccept.Visible = true
		task.wait(3)
		debounce = false
	end
end)

LocalScript:

local player = game.Players.LocalPlayer
local yesBtn = "Put Button Here" -- Change to your button

local rs = game:GetService("ReplicatedStorage")
local playerTranfer = rs.PlayerWhoHit

yesBtn.MouseButton1Click:Connect(function()
	playerTranfer:FireServer()
	player.PlayerGui.DeliveryGui.DeliveryAccept.Visible = false -- or change to the frame to make it invisible, I don't know the exact locarion
end)

2 Likes

From the server, you can just drop it in whoever’s PlayerGui and it replicates fine. In fact, that’s basically all StarterGui does but automatically. Then just use some code to determine who you want to have the GUI.

-- A server Script with the ScreenGui put inside it
local Players = game:GetService("Players")

local gui = script:FindFirstChildOfClass("ScreenGui")

local function shouldGiveGui(player)
    -- Make this however you determine who should get the GUI
    return player.DisplayName == "Synthx" -- example
end

Players.PlayerAdded:Connect(function(player)
    if shouldGiveGui(player) then
        local new = gui:Clone()
        new.Parent = player.PlayerGui
    end
end)

Edit: For your delivery script, you could just do all of that from the server and not use a remote event too.

1 Like