I am currently making a script for my game that spawns a bullet on mouse click and I want it to shoot in the direction that the mouse is. The issue im having however is with passing the mouse pos through FireServer to the server so i can spawn the ball and apply the impulse on the server for the other player to see. Can anyone help me? Here are my scripts:
Local Script
-- Rest of code is irrelevant, but can give if asked
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
local mouse = LocalPlayer:GetMouse()
local targetPosition = mouse.Hit.Position
print(targetPosition)
ballHandler:FireServer(LocalPlayer, targetPosition)
end
end)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("BallHandler")
local function spawnAndShootBall(LocalPlayer, targetPosition)
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local ball = game.Workspace.Bullets:WaitForChild("Balling"):Clone()
ball.Parent = game.Workspace.Bullets
ball.Anchored = false
ball.BallScript.Enabled = true
ball.Position = character:WaitForChild("RightHand").Position + Vector3.new(0, 1, 0)
if ball then
print("Ball spawned")
local direction = (Vector3.new(0, targetPosition.Y, targetPosition.Z) - Vector3.new(0, ball.Position.Y, ball.Position.Z)).unit * 50
ball:ApplyImpulse(direction)
else
warn("Ball not found")
end
end
remoteEvent.OnServerEvent:Connect(function(player, targetPosition)
spawnAndShootBall(player, targetPosition)
end)
The main issue that happens is when i print targetPosition in server script, it just print the player, and not the value i tried to send over.
** You are now Level 1! **