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

Why won't it say the things name when i activate the gun?

script.Parent.Activated:Connect(function(hit)
	print(hit.Name)
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

2 comments

0

You should use the player's mouse to find the target.

0

Really man you only provided us a piece of code and that's it? Atleast tell us the script's hierachy and the type of script. And also hit isn't a valid parameter if the Activated event of the tool: https://developer.roblox.com/api-reference/event/Tool/Activated

1 answer

✓ Accepted answer

The Activated event doesn't return any arguments, and therefore, hit is nil. You can get the mouse that's being used by the client by either using the GetMouse function or through an argument from the Equipped event.

local mouse = game.Players.LocalPlayer:GetMouse()

script.Parent.Activated:Connect(function()
    print(mouse.Target.Name) --mouse.Target is the object in 3D space the mouse is pointing to
    game.ReplicatedStorage.RemoteEvent:FireServer() --You can also send the mouse target to the server
end)

3 comments

0

15:47:52.598 - Players.bluemountainlion.Backpack.Handgun.PullGun:4: attempt to index field 'Target' (a nil value)

0

15:47:52.598 - Players.bluemountainlion.Backpack.Handgun.PullGun:4: attempt to index field 'Target' (a nil value)

0

you forgot to put Target as a paramater

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