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

Adding OnPlayedAdded to this? [ANSWERED]

Asked by 7 years ago
Edited 7 years ago

this is the whole code. and it works in studio

function onClicked()

    local Name = game.Workspace.Quest1.Name
    local Quest = game.Players.LocalPlayer.PlayerGui.Main.Quests.Frame
    Quest.CName.Text = Name
end 
script.Parent.ClickDetector.MouseClick:connect(onClicked)



i tried game.Players.PlayerAdded:connect(function) it failed

please help?

image of it not working / what im wanting

http://tinypic.com/view.php?pic=24gq99v&s=9#.V3k6QWgrKUk

function onClicked(hit)

        local Name1 = hit.Parent.Name
        local Name2 = game.Workspace.Quest1.Name
        local Quest = game.Players[Name1].PlayerGui.Main.Quests.Frame
        Quest.CName.Text = Name2
    end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

with that code, it outputs

11:20:15.210 - Players is not a valid member of Players 11:20:15.211 - Script 'Workspace.Quest1.Script', Line 5

0
Why do you need a player added event? User#11440 120 — 7y
2
Let me guess, server script? Or is it a LocalScript under workspace? M39a9am3R 3210 — 7y
0
it needs player Added for the gui User#12356 0 — 7y
0
it's a regular script btw User#12356 0 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

This is an ClickDetector event. LocalPlayer is only used in local scripts, but this is a server script. Here is a much easier script if you want it on joined.

game.Players.PlayerAdded:connect(function(plr)
    local Name = plr.Name
    local Quest = plr.PlayerGui.Main.Quests.Frame
    Question.CName.Text = Name
end)

However, if you want to keep it as a click event, it will only work in non-filtering enabled games. This would be the proper code.

function onClicked(hit)
    if hit.Parent:FindFirstChild("Humanoid") then   
        local Name = hit.Parent.Name
        local Quest = game.Players[Name].PlayerGui.Main.Quests.Frame
        Question.CName.Text = Name
    end
end 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

That's about it. Happy scripting! I hope I helped.

0
i got it. i just had to fix errors in other scripts. but im pretty sure your second script helped me. thanks :) User#12356 0 — 7y
0
Your welcome! GetEnveloped -7 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

On line 4 I see you use game.Players.LocalPlayer which only works in local scripts, and I think PlayerAdded only works on server scripts (or you used Players.OnPlayerAdded instead of Players.PlayerAdded)

0
Btw ClickDetector passes an argument which is the player who clicked the part xxracerdudexx 75 — 7y
0
Workspace.Quest1(this is a model to be clicked)(clickDetector is a child of Quest1).Script( a child of Quest1) User#12356 0 — 7y
0
and i knew it was there. i was using it to test on studio User#12356 0 — 7y

Answer this question