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

Why can't I print a players name with a server script that's in a tool?

I'm trying to print the players name but it isn't working and I can't figure out where the error is?

local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local Active = false
script.Parent.Activated:Connect(function()
	if Active == false then
		Active = true 
		animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animation) 
		animation:Play()
		animation.Stopped:Wait()
		print(player.Name)
		wait(1)
		Active = false
	end	
end)


script.Parent.Unequipped:Connect(function()
	animation:Stop()
end)

3 comments

0

Everything else works fine but the script breaks when I add print(player.Name)

0

Do you get any errors in the output? Print just player instead of player.name and see what happens.

0

When I do print("player") it prints "nil"

1 answer

Nvm I figured it out. It's because the script is running before the tool gets placed inside the character. It can be solved if I change

local player = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)

to

local player = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent) or script.Parent.Parent.Parent

1 comment

0

what does script.Parent.Parent in getplayerfrom character referring to?

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