Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Adding OnPlayedAdded to this? [ANSWERED]

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

4 comments

0

Why do you need a player added event?

2

Let me guess, server script? Or is it a LocalScript under workspace?

0

it needs player Added for the gui

0

it's a regular script btw

2 answers

✓ Accepted answer

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.

2 comments

0

i got it. i just had to fix errors in other scripts. but im pretty sure your second script helped me. thanks :)

0

Your welcome!

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)

3 comments

0

Btw ClickDetector passes an argument which is the player who clicked the part

0

Workspace.Quest1(this is a model to be clicked)(clickDetector is a child of Quest1).Script( a child of Quest1)

0

and i knew it was there. i was using it to test on studio

This discussion is preserved as it was. New answers, comments, and votes are closed.