Playeradded not working on local script?

Note:

  1. I am not testing this alone/on studio
  2. there are no errors
  3. the script may be a little weird bc i repurposed my death screen script as a test, YES i’ve tried all the other ways you can find by google search.
  4. script in starterplayerscripts
local Players = game:GetService("Players")






local Player = game:GetService("Players").LocalPlayer

local function onJoin()
	local timeof = Players.LocalPlayer.PlayerGui:WaitForChild("timeof")
	local sun = timeof.Frame.sun
	if game.Lighting.ClockTime > 0 or game.Lighting.ClockTime < 17.7 then
		game.SoundService.creek:Stop()
		game.Players.LocalPlayer.PlayerScripts.LocalBackgroundMusic.BGM.Volume = 0
		game.Players.LocalPlayer.PlayerScripts.LocalBackgroundMusic.BGM.PlaybackSpeed = 0
		sun.Image = "http://www.roblox.com/asset/?id=((idhere))"
		game.SoundService.creek:Play()
	end
	end
Players.PlayerAdded:Connect(onJoin)
Player.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")

end)

dont use player added on ur client u can use character added, if u would like to do something with your own character just do

local Player = game:GetService("Players").LocalPlayer
Player.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")

end)

As @NoDripDylan1 suggested, you dont need to use PlayerAdded or CharacterAdded in a local script, unless you want to run a function everytime another player joins.

You can simply do this:

local Player = game.Players.LocalPlayer
local CHAR = Player.Character or Player.CharacterAdded:Wait()
local HUM = CHAR:WaitForChild("Humanoid")
1 Like

PlayerAdded should always be used on the server.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
         ...
    end)
end)
1 Like

Instead of doing:

Players.PlayerAdded:Connect(onJoin)

Just call onJoin itself and you should have the effect you desire:

onJoin()

Thank you all! i am very grateful for all the help i got!! the solution has been found!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.