Recently I’ve been working on some “FPS Framework” but I kept getting this error from the server script:
Server code:
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("Shoot")
Remote.OnServerEvent:Connect(function(guy, position)
local Speed = 500
local Bullet = game.ReplicatedStorage.Projectiles.Bullet:Clone()
Bullet.Parent = workspace
Bullet.CFrame = position
Bullet.Velocity = Bullet.CFrame.lookVector * Speed
end)
The main framework local script:
local guy = game.Players.LocalPlayer
local mouse = guy:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ViewmodelStorage = ReplicatedStorage:WaitForChild("ViewmodelStorage")
local TargetViewmodelName = script.Name
local Viewmodel = ViewmodelStorage[TargetViewmodelName]:Clone()
Viewmodel.Parent = workspace
local position
local HRP = Viewmodel:WaitForChild("HumanoidRootPart")
-- settings
local FOV = 90
-- local Projectile = "Default"
local function attachVM()
HRP.CFrame = workspace.CurrentCamera.CFrame
workspace.CurrentCamera.FieldOfView = FOV
position = Viewmodel[script.Name].Handle.Attachment.CFrame
end
mouse.Button1Down:Connect(function(input)
print("Pew")
ReplicatedStorage.Remotes.Shoot:FireServer(guy, position)
end)
RunService.RenderStepped:Connect(attachVM)
My scripts are probably not ideal and their messy. I don’t care about that, I care more if I can get this working.
Thanks.
It does? Have you bothered printing it out. It’s also in the documentation for fire server, there is no need to do guy in the first parameter.
-- Include additional data when firing the event
remoteEvent:FireServer(BrickColor.Red(), Vector3.new(0, 25, 0))
So currently your remote function is returning 2 guys in the parameters because of the built in parameter.
Note that the connected function (lines 6-12) will receive the Player who fired the event as its first parameter ( player ), along with any additional parameters passed from the FireServer() call.
I would do more print debugging if I were you. A good trick is using a variadic function to print all the parameters and make sure you are passing in variables in the proper order. Otherwise it’s your loss and your problem.
Attachment depending on its parent has a different position, if u want the global position of it, I suggest getting the “WorldPosition” instead, basically if its parented to a part its “Position” can be Vector3.new(0,0,0) while its “WorldPosition” will be Vector3.new(-75.392, 0.5, 26.54)
local guy = game.Players.LocalPlayer
local mouse = guy:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ViewmodelStorage = ReplicatedStorage:WaitForChild("ViewmodelStorage")
local TargetViewmodelName = script.Name
local Viewmodel = ViewmodelStorage[TargetViewmodelName]:Clone()
Viewmodel.Parent = workspace
local thingPos
local mouseHit
local HRP = Viewmodel:WaitForChild("HumanoidRootPart")
-- settings
local FOV = 90
-- local Projectile = "Default"
local function attachVM()
HRP.CFrame = workspace.CurrentCamera.CFrame
workspace.CurrentCamera.FieldOfView = FOV
thingPos = Viewmodel[script.Name].Handle.Fire.Position
mouseHit = mouse.Hit.lookVector
end
mouse.Button1Down:Connect(function(input)
print("Pew")
print(thingPos)
ReplicatedStorage.Remotes.Shoot:FireServer(guy, thingPos, mouseHit)
end)
RunService.RenderStepped:Connect(attachVM)
Why are you still passing the guy variable? The first parameter will always pass the Player onto an OnServerEvent, you don’t need to reference it again
Also you should just be getting the mouse.Hit or mouse.Hit.Position of the mouseHit variable, no need to get its LookVector
local guy = game.Players.LocalPlayer
local mouse = guy:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local ViewmodelStorage = ReplicatedStorage:WaitForChild("ViewmodelStorage")
local TargetViewmodelName = script.Name
local Viewmodel = ViewmodelStorage[TargetViewmodelName]:Clone()
Viewmodel.Parent = workspace
local thingPos
local mouseHit
local HRP = Viewmodel:WaitForChild("HumanoidRootPart")
-- settings
local FOV = 90
-- local Projectile = "Default"
local function attachVM()
HRP.CFrame = workspace.CurrentCamera.CFrame
workspace.CurrentCamera.FieldOfView = FOV
thingPos = Viewmodel[script.Name].Handle.Fire.Position
mouseHit = mouse.Hit.Position
end
mouse.Button1Down:Connect(function(input)
print("Pew")
print(thingPos)
ReplicatedStorage.Remotes.Shoot:FireServer(thingPos, mouseHit)
end)
RunService.RenderStepped:Connect(attachVM)
…?
Also the Velocity property is known to be deprecated, you might wanna use a BodyVelocity object instead to move the Bullet so that it can maintain a constant speed