So I have a flashlight tool. When you press F, the flashlight should be equipped. But it isn’t working. I’ve figured out that it’s due to me not having CharacterAutoLoads on, but I’m not sure what the issue is.
LocalScript in StarterPlayerScripts:
local ContextActionService = game:GetService('ContextActionService')
local Players = game:GetService('Players')
local sound = script:WaitForChild("equip1")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = game.StarterPack.Flashlight
local function equipAction(name, state, obj)
if state == Enum.UserInputState.Begin then
if character:FindFirstChild(tool.Name) then
character.Humanoid:UnequipTools()
else
character.Humanoid:EquipTool(tool)
sound:Play()
end
end
end
ContextActionService:BindAction(
'equipKeybind',
equipAction,
false,
Enum.KeyCode.F
)
Help!
Also, the equip sound does play when I press F. So it’s a problem with actually equipping the tool.
local sound = script:WaitForChild("equip1")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = game.StarterPack.Flashlight
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input,gp)
if gp then return end
if input.KeyCode == Enum.KeyCode.F then
if character:FindFirstChild(tool.Name) then
character.Humanoid:UnequipTools()
else
character.Humanoid:EquipTool(tool)
sound:Play()
end
end
end)
I don’t mean to be rude but uh, am I just semi-ignored in the solution because someone beautified my text by using markdowns which makes it stand out more? Because it would seem that even though I answered first, I take no credit. Also, going back I would recommend to use character:WaitForChild(“Humanoid”):EquipTool() and character:WaitForChild(“Humanoid”):UnequipTools to wait for the character’s humanoid. You can see more information on WaitForChild here: Instance:WaitForChild. Also, ContextActionService is totally preferenced but for future reference I recommend using UserInputService as its easier in my opinion. Also, even though it was wrong to use StarterPack as seen by the solution, it also seems wrong not to use game:GetService(“StarterPack”) rather than game.StarterPack when you used GetService for getting the Players and ContextActionService service’s. Even though it seems wrong to discuss credit, seeing that mile didn’t know that I was gonna post a solution before them, it just angers me for some odd reason to see someone mark the solution for someone that posted after I posted about my take. Also, if you marked mile’s solution because of it being more clear on how to change StarterPack to Backpack, then I recommend to learn some basics of programming (don’t mean to be rude here either). I’m probably going to regret saying this seeing as I will probably be reported even though I think that I did absolutely nothing wrong. I know you’re most likely a newbie programmer/coder/scripter and didn’t realize this or see my post, but I just couldn’t help but talk open about it. Other than that, I feel that theres no more to discuss on this topic, and I hope that everybody is having a good day. P.S. I learned how to program by watching tutorials such as tutorials made by AlvinBlox and TheDevKing. Also, please do not start an argument over this.
Sorry dawg, I actually should’ve given you the solution cuz I did end up using script.Parent. I know I debated on who to give the solution to, and I’ll redo it and give you it. I kinda just feel llike you might be getting upset over useless internet points, and that mighta been a bit over the top.