I tried using a normal script instead of a local script but I keep getting errors like "this is not a valid member of model" my code was originally in a localscript but when i move it to a normal script I get the errors. my script is down.
local plr = game.Players.LocalPlayer local char = plr.Character local mouse = plr:GetMouse() local tool = script.Parent local event = game.ReplicatedStorage:WaitForChild("RemoteEvent") tool.Activated:Connect(function() local hit = mouse.Hit Event:FireServer(Hit) end)
should I get rid of the local in front of my variables?
Try this, also sorry if there are some errors this was typed on the phone.
if script.Parent.Parent.ClassName ~= "Model" then local plr = script.Parent.Parent elseif script.Parent.Parent.ClassName == "Model" then local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent) end local char = plr.Character local mouse = plr:GetMouse() local tool = script.Parent local event = game.ReplicatedStorage:WaitForChild("RemoteEvent") tool.Activated:Connect(function() local hit = mouse.Hit Event:FireServer(hit) end)
At line 1 you attempted to call LocalPlayer which can only be accessed by a local script. Now how I got to my edit of that line is simple, it checks if the tool is equipped via method of if the tool is a child of players or the character, depending on the situation the variable will be different. Also do not remove the "local" before each variable, its better on the script and is good practice. Also on your original line 8 you incorrectly notated "hit".Remember variables are case sensitive.