Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Body Position objects are not working in the gun script, any help?

The code doesn't work when it tries to put in a vector3 value, though I don't know why. Client Script

script.Parent.Equipped:Connect(function(Mouse)
	script.Parent.Activated:Connect(function()
		local MousePos = Mouse.Hit.p
		game.ReplicatedStorage.RemoteEvent:FireServer(MousePos, script.Parent.Handle.position)
	end)
end)

server script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Plr,MousePos,GunPos)
	local CloneBullet = game.ServerStorage.Bullet:Clone()
	print(MousePos)
	CloneBullet.Position = GunPos
	CloneBullet.BodyPosition.Position = Vector3.new(MousePos)
	CloneBullet.Parent = game.Workspace
end)

The bullet is just a sphere with a body position object in it.

1 answer

My answer is that I found an error with the "Vector3.new", because the script doesn't know what the X,Y and Z is.

Instead of just putting "MousePos", try

CloneBullet.BodyPosition.Position = Vector3.new(MousePos.X,MousePos.Y,MousePos.)

so the script understands where to go with your mouse.

(note: i am not that much of a scripter but I attempted to see the problem and pictured how to fix it)

2 comments

0

mouse.Hit.Position returns the x,y and z position of it, so its pointless

0

ok man, you can just negatively comment but it's not gonna help anyone.

This discussion is preserved as it was. New answers, comments, and votes are closed.