Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make guns show on server side?

Asked by
Nikkulaos 229 Moderation Voter
6 years ago

I am working on an FPS and i got it all done and all, but the weapons only show on the client (they are placed in the camera)

So basically I tried making a remote event and cloning the weapon through the server to weld it to the weapon in the camera, but it wont work.

I am trying to find a way to do it so that the other players can see your gun aswell.

Client script:

Weapon = Resources.Weapons[Settings.Primary.Value]:clone()
Weapon.Parent = Camera
game.ReplicatedStorage.ServerGun:FireServer(Weapon)

Server script:

game.ReplicatedStorage.ServerGun.OnServerEvent:connect(function(Player, cgun)
        local gun = Player.PlayerGui.Client.Settings.Primary.Value
        local sgun = game.Lighting.Resources.ServerWeapons:FindFirstChild(gun):Clone()
        sgun.Parent = Player.Character
        local weld = Instance.new("Weld", sgun)
        weld.Part0 = sgun
        weld.Part1 = cgun.Handle
        weld.C0 = CFrame.new(0,0,0)*CFrame.Angles(0,math.pi/2,0)
end)

This works when i play in studio, but not in game or on local servers.

If you can help then please do!

Thanks!

3 answers

Log in to vote
1
Answered by
Vexture 179
6 years ago

Because cgun doesn't actually exist server-side, the server can't see the actual object you're talking about. Rather than sending the cgun itself and welding sgun's handle to something that doesn't actually exist from the server's perspective, just weld the sgun to the character similar to how you've welded it to the viewmodel. You won't get an exact replica of what the client's viewmodel actually shows, but you'll be able to see the gun.

If you want, instead of using welds for the server side gun model, you can have the client send raw CFrame data sent as a RemoteEvent argument to the server so the server can then change the relevant gun model's position on that interval. Note, though, that this may cause strain on the server because it would require constant updating.

So, to sum it up: You can just weld the server gun model to the character's torso, or you can send cframe data to the server which would go through a table of all existing sgun models currently in workspace and update their position based on what the client sends them.

Actually, for best results, you could get the server to relay that CFrame data right back to every other client. This way, you can also change arm positions client-side on every client and edit other things without possibly messing with character movement physics if you change too much server-side.

Hope this helped! There's not much code here, but I hope this answered your question and showed you what went wrong. Hopefully these options will help you! :)

Ad
Log in to vote
0
Answered by 6 years ago

Simply parent the gun into workspace instead? Usually I put things in the camera object so only certain players can see it. If you put it in workspace though, everyone should see it.

Also why are you parenting the gun into the camera anyways? I’m just curious.

0
Even when i parent it to workspace though, only the player can see it (this is FE btw). And yes, most of the scripts are client sided. The animations and stuff for the gun look smoother in the client (because of renderstepped) Nikkulaos 229 — 6y
Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

Simply create the gun in a server - sided script, so that every player can see it.

Answer this question