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

How would I make this work? (don't ignore this time please)

Asked by
JJ_B 250 Moderation Voter
8 years ago

I made a personal message GUI, and inside a button is this LocalScript. However, I don't know how to parent the PM GUI it makes to the recipient's PlayerGui. I did this script.

function pm()   
    local n = game.Players.LocalPlayer.Name
    local m = script.Parent.Parent.username.Text
    local b = script.Parent.Parent.pm.Text
    local p = game.ReplicatedStorage.pm:Clone()
    p.Frame.author.Text = "from " .. n
    p.Frame.text.Text = "" .. m
    p.Parent = game.Players:FindFirstChild(m).PlayerGui

end

script.Parent.MouseButton1Down:connect(pm)

I need to know how I would do line 8 correctly. Can anyone help?

0
Am i blind or missing something but why is Text said twice in measure 7 iSvenDerp 233 — 8y
0
text is the name of the TextLabel. Text is the actual Text property. JJ_B 250 — 8y
0
we didn't ignore it, it was removed. HungryJaffer 1246 — 8y
0
I recommend using a [RemoteEvent](http://wiki.roblox.com/index.php?title=API:Class/RemoteEvent) instead. Validark 1580 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
function pm()   
    local n = game.Players.LocalPlayer.Name
    local m = script.Parent.Parent.username.Text
    local b = script.Parent.Parent.pm.Text
    local p = game.ReplicatedStorage.pm:Clone()
    p.Frame.author.Text = "from " .. n
    p.Frame.text.Text = "" .. m
    p.Parent = game.Players:FindFirstChild(m).PlayerGui

end

script.Parent.MouseButton1Down:connect(pm)

Well, there's not always a Player in Players named what m is. Say I put something like nibzor in the textbox and there's no nibzor in the game. What happens? It returns an ugly error. So how do we fix this? We check if there is someone with said name. But how do we do that? by using an If Statement.

So, it would look like this.

if game.Players:FindFirstChild(m) then
 p.Parent = game.Players:FindFirstChild(m).PlayerGui
    else print("No one with that name was found")
end

And your finished code..

function pm()   
    local n  =  game.Players.LocalPlayer.Name
    local m  =  script.Parent.Parent.username.Text
    local b  =  script.Parent.Parent.pm.Text
    local p  =  game.ReplicatedStorage.pm:Clone()
    p.Frame.author.Text = "from " .. n
    p.Frame.text.Text = "" .. m
if game.Players:FindFirstChild(m) then
     p.Parent = game.Players:FindFirstChild(m).PlayerGui
        else print("No one with that name was found")
    end
end

script.Parent.MouseButton1Down:connect(pm)
Ad

Answer this question