|
How would I change this hint to GUI? I want the GUI to be only seen when they are on touched with them.
function Touched(hit)
m = Instance.new("Hint")
m.Parent = game.Workspace
m.Text = ("WARNING: Shield Defences Online")
wait(1)
m:Remove()
e = Instance.new("Explosion")
e.Parent = game.Workspace
e.Position = hit.Position
e.BlastPressure = 10
e.BlastRadius = 5
end
script.Parent.Touched:connect ("Touched") |
|
nixpcJoin Date: 2012-02-05 Post Count: 15425 |
m.Parent = hit.Parent |
|
|
If I was weather to change it to a GUI instead of a hint would it be.
script.frame.clone()
Did i do this correct? |
|
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Clone a premade gui into the player's playerGui.
Say you have a gui in ServerStorage named 'TestGui'?
Edit accordingly
local guiName = 'TestGui'
local gui = game.ServerStorage:FindFirstChild(guiName)
script.Parent.Touched:connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then if gui then gui:Clone().Parent = plr.PlayerGui end end
end) |
|
|
Okay like this?
function Touched(hit)
local guiName = 'TestGui'
local gui = game.ServerStorage:FindFirstChild(guiName)
script.Parent.Touched:connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then if gui then gui:Clone().Parent = plr.PlayerGui
e = Instance.new("Explosion")
e.Parent = game.Workspace
e.Position = hit.Position
e.BlastPressure = 10
e.BlastRadius = 5
end
script.Parent.Touched:connect (Touched) |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
No, assuming 'TestGui' is valid.. dis.
local guiName = 'TestGui'
local gui = game.ServerStorage:FindFirstChild(guiName)
script.Parent.Touched:connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then if gui then gui:Clone().Parent = plr.PlayerGui
e = Instance.new("Explosion",workspace)
e.Position = hit.Position
e.BlastPressure = 10
e.BlastRadius = 5
end)
|
|
|
Okay , thank you for helping
What does his line do?
local guiName = 'TestGui' |
|
|
bloxx97Join Date: 2008-01-08 Post Count: 40 |
Essentially GUIs work a lot like functions where you need to create them (and for that matter do not need to create them live while the server is running, but can do it personally in studio mode) and then move them into the player's PlayerGui when the Event triggers your function.
For a GUI to make messages, you're actually going to have to create a GUI that mimics personal messages. Gonna have to create the background, make it black and semi-transparent, and then add a Text Box to it, and then have the GUI's text and background disappear after a few seconds or at the click of a GuiButton that looks like X.
GUIs are a pain in the ass. I bet there's a plugin that allows you to drag and drop GUI elements so that you don't have to do all the manual positioning like in the good old days.
http://wiki.roblox.com/index.php?title=API:Class
If you scroll down to GUI, there's a list of a few GUI classes and then a massive list of Events. If you mean you want them to only see the hint-like GUI when they are physically touching the Part/block/brick/button and then NOT see it when they move off of it - you can use the TouchStarted and TouchEnded Events instead of Touch.
And for what it's worth - this is the actual Touched event syntax pulled from the wiki.
function onTouch(obj)
script.Parent.Transparency=0.8
script.Parent.CanCollide=false
wait(2)
script.Parent.Transparency=0
script.Parent.CanCollide=true
end
script.Parent.Touched:connect(onTouch)
--as in no quotes when you call your function with connect at the end.
--However you've taught me something because I had trouble understanding the event handler (hit). I thought this script was cheese until I searched around to find the event handler refers to the Part that is touched. Because really in my mind I would just set the explosion to script.Parent - why would anyone even refer to the same brick in two different ways if the script is already in the Part that it wants to listen to?
|
|