I have a script that is supposed to fire a projectile out of a parent tool, however the script ends when I try to define the players mouse
local plr = script.Parent.Parent:findFirstChild("Humanoid") local player = game.Players:GetPlayerFromCharacter(plr) local mouse = player:GetMouse()
This is what I have, however it doesn't work.
Alternatively I have tried
local plr = script.Parent.Parent local name = plr.Name local player = game.Players.name local mouse = player:GetMouse()
The tool parent ladder is
script > tool > players backpack/player(when held)
Any ideas on how to fix this?
The ONLY way this would work, is by setting up a RemoteEvent that would constantly firing, firing the mouse from a LOCAL script. It's recommended you get the player's mouse locally, since it's the most efficient way.
For a RemoteEvent / FilteringEnabled method (Which is highly advised you learn how to use because it's a good system), you're going to need; A localscript, A normal server script, A remote event.
local player = game:GetService'Players'.LocalPlayer local mouse = player:GetMouse() local event = script.Parent.RemoteEvent mouse.Button1Down:connect(function() event:FireServer() end)
That code will go into the localscript.
local event = script.Parent.RemoteEvent event.OnServerEvent:connect(function() -- Your projectile code will go here. end)
This code will go into the Server script.
I'm not entirely sure if that is the best method, and you could most likely improve it.
i can only say that you must put this script in StarterPlayer.StarterPlayerScripts:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() --it works for me in StarterPlayerScripts workspace.yes.Activated:Connect(function() mouse.Button1Down:connect(function() end) end)
i know you wanted to know how to put it into a tool but it works like this for me