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

Why Am i Not able to access the Player Added Event?

Please respond, I have been asking for a while now.

I have a code that is supposed to run on Player Added. It's a server script and it's under an image button in Screen GUI. However "hekki" is not printing when I run the program. What's the issue?

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

print("hekki")
script.Parent.MouseButton1Click:Connect(function()
	print("hello!")
	--local character = player.Character or player.CharacterAdded:Wait()
	--local player = game.Players:GetPlayerFromCharacter(Character)
	local SG = player.StarterGear
	local tool = player.Character:FindFirstChildOfClass("Tool")
	--local name = tool.Name
	if tool then
		print("hello!!!")
		tool:Destroy()
		
	end
	if SG:FindFirstChild(tool.Name) then
    	SG[tool.Name]:Destroy()
	end
	
end)
end)

2 comments

0

What type of script is this?

0

You actually don't need the Players.PlayerAdded. You only have to put the code into a localscript since this is a script inside a player's screengui and get the player by doing game.Players.LocalPlayer

1 answer

ScreenGUI is only replicated in the player's files after the player's character is created thus it can't run on player being added to the game because at that point the player has yet to get a character loaded, player added events should be used in ServerScriptService for best results

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