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

local player with a tool?

hello... im quite a good scripter but i never know how to do the thing of local the player i want to make tool that when clicked it puts a shot sound and put a bullet front of your torso and it moves front like a shot but i have the problem that the bullet needs to move to the "player" torso.. heres the script

function onActivation() shot:Play() local player = workspace.character local obj=script:FindFirstChildOfClass("Gun"):clone() obj.Parent=workspace obj:SetPrimaryPartCFrame(Player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-3)) end

and im getting the error: character its not a valid member of workspace player

1 answer

✓ Accepted answer

For someone who’s quite a good scripter, you sure do need to learn about errors!

All jokes aside, it’s just what the error says, character is not a valid member of workspace. If you are trying to make this in a local script, getting the player is as easy as game.Players.LocalPlayer, and if it’s not a local script, you can simply use the tool’s parent (which will ALWAYS be the player’s character if the tool is being held) to get your player’s character, and then the GetPlayerFromCharacter() method.

Another issue I noticed in your code! “Gun” is not a ClassType. As nice as it’d be to be able to simply Instance.new(“Gun”) and have a perfectly working gun system, that’s not how it works. I think you’re looking for :FindFirstChild(“Gun”), which finds the first child with the name of gun as opposed to the class.

So do these steps!

  1. Use the above suggestions to fix your code
  2. Read about errors, they’re very helpful in a scripter’s endeavors
  3. Take some time to reflect, and learn a lesson in humility

Hope I could help!

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