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
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.
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)