Hit is not a valid member of Player "Players.kninja888"

Hello! my friend was trying to code a tank bullet system, but it isnt working.

it is a local script that activates a server script:

local script:

local Plr = game.Players.LocalPlayer
local Mse = Plr:GetMouse()

local evt = script:WaitForChild("RemoteEvent")

Mse.Button1Down:Connect(function()
    evt:FireServer(Mse)
end)

server script:

local ret = script.Parent:WaitForChild("RemoteEvent")

local bul = game.ReplicatedStorage.Bullet

ret.OnServerEvent:Connect(function(mouse)
    local clo = bul:Clone()
    clo.Parent = workspace
    clo.CFrame = script.Parent.Parent.ShootPart.CFrame
    clo.Value.Value = Vector3.new(mouse.hit.p)
end)

the script for the bullet (it is in replicated storage but then is put in workspace)

local TweenService = game:GetService("TweenService")

local part = script.Parent

local goal = {}
goal.Position = Vector3.new(script.Parent.Value.Value)
goal.Color = Color3.new(0.3, 0, 0)

local tweenInfo = TweenInfo.new(5)

local tween = TweenService:Create(part, tweenInfo, goal)

tween:Play()

Since Mouse.Hit uses the players mouse, of which it is only on the client, therefore can only be called from the client. Try sending Mouse.Hit.P from the client to the server, instead of all the mouse parameters.

i tried that, and the bullets move to the center.

Then use the CFrame from Mouse.Hit instead of Mouse.Hit.P. And change any parts you’re comparing it to, to fit a CFrame value.

Workspace.kninja888.Fire.Script:9: invalid argument #1 to ‘new’ (Vector3 expected, got Instance)

You didn’t define the player sent from the remote event to the server. It’s always sent whenever using a RemoteEvent. So add a “plr” or “player”, or anything similar as the first argument to the server side of the RemoteEvent.
e.g.

ret.OnServerEvent:connect(function(plr,mouse) --server side

It doesnt work, actually i might just try moving the part insteaf

Try this and see if anything changes:

--Local Side
local Plr = game.Players.LocalPlayer
local Mse = Plr:GetMouse()

local evt = script:WaitForChild("RemoteEvent")

Mse.Button1Down:Connect(function()
    evt:FireServer(Mse.Hit.Position)
end)

--Server Side
local ret = script.Parent:WaitForChild("RemoteEvent")

local bul = game.ReplicatedStorage.Bullet

ret.OnServerEvent:Connect(function(Player, mousePosition)
    local clo = bul:Clone()
    clo.Parent = workspace
    clo.CFrame = script.Parent.Parent.ShootPart.CFrame
    clo.Value.Value = Vector3.new(mousePosition)
end)

It may also depend on where you put your RemoteEvent from

1 Like

i might try that later, thanks

Alright soo… it doesnt work, i think the problem is with the bullet because it is only going to the center and not the mouse.

This might be the reason why, can you print what the Value.Value is? If it prints nothing or nil, then I think you may need to change the Velocity of the object instead using a BodyVelocity

Well, the part is not using a bodyvelocity, it is using a tween

Could you try changing this

    clo.Value.Value = Vector3.new(mousePosition)

To this?

    clo.Value.Value = Vector3.new(mousePosition) * 50

Change the arguments to (player, mouse) as the first argument OnServerEvent returns is a player, which explains the error.

Change your script to this:

Local Script:

local Plr = game.Players.LocalPlayer
local Mse = Plr:GetMouse()

local evt = script:WaitForChild("RemoteEvent")

Mse.Button1Down:Connect(function()
    evt:FireServer(Mse.Hit.p)
end)

Server Script:

local ret = script.Parent:WaitForChild("RemoteEvent")

local bul = game.ReplicatedStorage.Bullet

ret.OnServerEvent:Connect(function(player,mousePos)
    local clo = bul:Clone()
    clo.Parent = workspace
    clo.CFrame = script.Parent.Parent.ShootPart.CFrame
    clo.Value.Value = mousePos
end)

Hopefully this works!