You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? When you touch a part, a GUI pops up.
What is the issue? It does not work properly.
What solutions have you tried so far? I have looked at multiple forum posts and none of them seem to suit me.
Here is the script:
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
game.Players.LocalPlayer.PlayerGui.LoadingGUI.Background.Visible = true
end
end)
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
game.Player:GetPlayerFromCharacter(other.Parent).PlayerGui.LoadingGUI.Background.Visible = true
end
end)
i.LoadingGUI.Background.Visible = true
end
end)
Try using remote events. What worked for me was to have the server check for collisions, and then fire an event. When the client detects the event, make the GUI visible.
So this is the script that brings the Gui up on collision with the part. It is a local script in the model:
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
game.Player:GetPlayerFromCharacter(other.Parent).PlayerGui.LoadingGUI.Background.Visible = true
end
end)
This script is the just a regular serverscript located in the model that clones the Loading gui:
No need to clone the GUI, you can keep it in StarterGui keeping Visible = false.
local Brick = workspace.BLAHBLAH.BLAHBLAH -- redirect this to your brick
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
game.Players.LocalPlayer.PlayerGui.LoadingGUI.Background.Visible = true
end
end)
What you could do is add this script to ServerScriptService, then add the GUI inside the script. Then, once the Part in Workspace is touched, then you can :Clone() the GUI to the client’s PlayerGui.
If you want the Gui to be cloned, simply remove the code mentioned above and make sure Visible = true. In a server script, you can simply clone and remove.
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
script.Parent:WaitForChild("LoadingGUI"):Clone().Parent = game.StarterGui
end
end)
local Brick = script.Parent.SCIParts.Touch
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
script.Parent:WaitForChild("LoadingGUI"):Clone().Parent = game.Players:GetPlayerFromCharacter(other.Parent) --not starterGui then everyone see's it.
end
end)
Were gonna use the above code but alter it a little bit
Brick.Touched:Connect(function(other)
if other.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = Player.PlayerGui
end
end)
Anyways I have no idea if this works but here you go.
I changed the script to a regular server script because the local script would not clone the GUI. But when I clone it into StarterGUI with the visibility on, it never appeared. It would always be blank. So when I tried to make the GUI visible with a line of code, I kept getting the same error. I do not know what to do.
There is no need of checking for humanoid, just check for the player. Don’t use WaitForChild() on the server script since the server is authoritative.
Also, you shouldn’t post scripts if you aren’t positive if it’s going to work or not.
Brick.Touched:Connect(function(other)
local Player = game.Players:GetPlayerFromCharacter(other.Parent)
if Player then
local Gui = script.Parent:WaitForChild("LoadingGUI")
local GuiClone = Gui:Clone()
GuiClone.Parent = Player.PlayerGui
end
end)
StarterGui get’s cloned to PlayerGui when a player joins. Therefore, you need to get the player who touched the part and then clone the Gui to the PlayerGui using remote events.
Here’s a demonstration.
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.ReplicatedStorage.RemoteEvent:FireClient(player) -- pass the arg for the player who touched it
end
end)
Then, you can use OnClientEvent and clone it to the player. Always handle UI on the client for immediate response.