script.Parent.Activated:Connect(function(hit)
print(hit.Name)
game.ReplicatedStorage.RemoteEvent:FireServer()
end)
✓ ANSWER ACCEPTED
Why won't it say the things name when i activate the gun?
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.

2 comments
You should use the player's mouse to find the target.
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