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

My script doesn't run anything after a certain point and it doesn't have any breakpoints?

game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function()
	local playerService = game:GetService("Players")
	--nothing runs after this point
	playerService.PlayerAdded:Connect(function (plr)
		plr.CharacterAdded:Connect(function (char) 
			local head = char:WaitForChild("Head")
		--source code I dont want to give away but nothing is wrong I tested it

im so confused

1 answer

✓ Accepted answer

.PlayerAdded only gets detected when a player joins the game. Since the player is already in the game when the event is fired, PlayerAdded can't fire. You don't need to use PlayerAdded to get the player. OnServerEvent has parameters you can use instead to get the player.

game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function(player) -- player parameter

end

The first default parameter is the player that fires the event.

Therefore,

game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function(player)
	local Character = player.Character
	local head = Character:WaitForChild("Head")
end

hope this helps

1 comment

0

thank you kind sir

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