What i want to do is clone a projectile from a prefabs folder in ReplicatedStorage, then put it in the workspace positioned at the weapon’s barrel (called ray in the hierarchy) and then propell it forward.
I have a localscript inside the player that detects player input, manages the gun, etc. and i have a server script that recieves values from the localscript (bullet prefab, barrel CFrame, damage and bullet speed)
It seems to work fine… accept for some reason the bullet spawns like 10 studs below the player.
I have tried printing both the position of the barrel and the position of the CFrame value passed to the server side script. they both print out the same value (sometimes they are slightly different, when the player moves for example, where it prints out the ray value, and the server recieves the value from the client script a bit later)
here are my two scripts:
–Server script:
local Debris = game:GetService(“Debris”)
game.ReplicatedStorage.ServerRemotes:WaitForChild(“Fire”).OnServerEvent:Connect(function(plr,
bullet, pos, baseDmg, speed)
local bolt = bullet:Clone()
bolt.Parent = game.Workspace
if bolt:FindFirstChild("BodyVelocity") then
local force = bolt.BodyVelocity
bolt.CFrame = pos
bolt.Position = pos.Position
force.Velocity = bolt.CFrame.LookVector * speed
Debris:AddItem(bolt, 5)
else
print("No BodyVelocity found, please add a BodyVelocity to the prefab.")
bolt:Destroy()
end
end)
.
.
.
.
–localScript
script.Activate.Event:Connect(function(gun)
local Canfire = true
local Projectile = game.ReplicatedStorage.Projectiles.PlasmaSmallBolt
local function onInputBegan(input, process)
if (process) then return; end
if (input.UserInputType == Enum.UserInputType.MouseButton1) then
if Canfire then
script.Timer:Fire()
game.ReplicatedStorage.ServerRemotes.Fire:FireServer(Projectile, gun.Ray.CFrame, 45, 100)
end
end
end
script.Timer.Event:Connect(function()
Canfire = false
wait(.2)
Canfire = true
end)
game:GetService("UserInputService").InputBegan:Connect(onInputBegan);
end)
–Video (may be a little hard to see)