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

how do i access a character from a tool?

Asked by 5 years ago

i am only able to find the player in game.players but i cant find the character in game.Workspace by using my tool

1 answer

Log in to vote
0
Answered by 5 years ago

the character can be found two ways. The first way is by using :FindFirstChild()

if game.Players.LocalPlayer then
local plr=game.Workspace:FindFirstChild(game.Players.LocalPlayer)
end

the other way(the one thats better to use) is by using plr.Character

local plr=game.Players.LocalPlayer.Character

also, you could just get the localplayer when the tool is equipped

local tool=script.Parent
local plrcheck=false
local plr
local debounce=false
tool.Equipped:Connect(function()

if plrcheck==false and not debounce then
debounce=true
plr=script.Parent.Parent

wait(0.1)
plrcheck=true
debounce=false
end


end


end)
0
Note that this only will work in a LocalScript. A Script (running on the server) will have a LocalPlayer of nil. WillieTehWierdo200 966 — 5y
0
i know, tools are localized EmbeddedHorror 299 — 5y
0
thats why i added the last one b/c it doesnt need a localscript EmbeddedHorror 299 — 5y
Ad

Answer this question