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

How to define a character in a server script?

Asked by 4 years ago

Hi, I am making an invincibility potion for my game that prevents the player from getting damage using the force field but I have no idea how to parent the forcefield to the character in a server script. This is my script.

local tool = script.Parent
local char = --How to define the character?--

tool.Activated:Connect(function()
    local FF = Instance.new("ForceField", char)
    wait(5)
    FF:Destroy()
end)

Please help me.

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

It's safe to assume that Tool.Parent refers to the Character Model when Equipped, therefore, it's best to allocate the avatar accordingly:

local Tool = script.Parent


Tool.Equipped:Connect(function()
    Character = Tool.Parent
end)

Tool.Activated:Connect(function()
    print(Character.Name.." used the Tool!")
end)
Ad

Answer this question