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.
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
--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
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
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)