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?

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.m.PlayerGui

end

script.Parent.MouseButton1Down:connect(pm)

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

1 answer

Log in to vote
0
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)

You are trying to find a child of Players named m. This will return nil, since there is nothing inside PlayerGui named m. But we can look for the string that m defined (the name) inside the PlayerGui by using FirstFIndChild.

0
This doesn't work :/ JJ_B 250 — 8y
0
The output says "attempt to index a nil value" JJ_B 250 — 8y
Ad

Answer this question