Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

This question has been solved by the original poster.

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)

0
Everything else works fine but the script breaks when I add print(player.Name) Michael_TheCreator 166 — 3y
0
Do you get any errors in the output? Print just player instead of player.name and see what happens. Rynappel 212 — 3y
0
When I do print("player") it prints "nil" Michael_TheCreator 166 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
what does script.Parent.Parent in getplayerfrom character referring to? WINDOWS10XPRO 438 — 3y
Ad

Answer this question