Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make a GUI show when a block is touched?

Asked by
Zripple 18
6 years ago
Edited 6 years ago
script.Parent (function(hit)
    game.StarterGui.ScreenGui.GoodJob.Visible = true
wait(10)
    game.StarterGui.ScreenGui.GoodJob.Visible = false
end)
0
local part = game.Workspace.Part part.Touched:Connect(function(hit) if hit.Parent.Humanoid then local screengui = script.Parent screengui.Enabled = true end end) kattenverzorger 23 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

Your issue is that you're attempting to change the object located in StarterGui. When a player loads into a game, the contents of this service are cloned into a folder in the player called PlayerGui. Thus, you want to change the objects in that folder. The problem is that you cannot access existing members of PlayerGui through the server, so we're going to have to use a Remote Event.

--Server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = Instance.new("RemoteEvent") --create remote
RemoteEvent.Parent = ReplicatedStorage
local part = workspace.Part

part.Touched:Connect(function(otherPart)
   local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent)
   if player then --ensure existence
      RemoteEvent:FireClient(player,"") --any data can be sent through the second argument
   end
end)

--Local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") --wait for remote
local player = game:GetService("Players").LocalPlayer

RemoteEvent.OnClientEvent:Connect(function(args) --the data you sent
   local Gui = player.PlayerGui:FindFirstChild("ScreenGui")
   if Gui then --ensure existence
      Gui.GoodJob.Visible = true
      wait(10)
      Gui.GoodJob.Visible = false
   end
end)

Resources:

:GetPlayerFromCharacter()

Remote Events


Accept and upvote if this helps!

Ad
Log in to vote
0
Answered by 6 years ago
local part = game.Workspace.Part

part.Touched:Connect(function(hit)

    if hit.Parent.Humanoid then
        local screengui = script.Parent.Parent
        screengui.Enabled = true
    end
end)

game.StarterGui.ScreenGui.TextLabel.LocalScript

Make sure you do it in the order above

Answer this question