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

Why does my gun fire all guns in the server when fired?

Asked by 5 years ago

Hi! I made a gun script, local script, and remote event to communicate between the local and server script. When two or more players have there guns out at the same time and I click to fire the gun all the players with their guns out will fire their guns. Here is the local script:

01local player = game.Players.LocalPlayer
02local character = player.CharacterAdded:Wait()
03local mouse = player:GetMouse()
04local tool = script.Parent
05 
06tool.Equipped:Connect(function()
07    tool.Activated:Connect(function()
08        local mouse_location = mouse.Hit.Position
09        local bullet_ray = Ray.new(tool.Main.CFrame.Position,(mouse_location - tool.Main.CFrame.Position).unit * 300)
10        local part,position = workspace:FindPartOnRay(bullet_ray,character,false,false)
11        game.ReplicatedStorage.Lee.fired:FireServer(character,mouse_location,position,part)
12    end)
13end)

Here is the server script:

01local tool = script.Parent
02local enabled = false
03UIS = game:GetService("UserInputService")
04 
05game.ReplicatedStorage.Lee.fired.OnServerEvent:Connect(function(player,character,mouse_location,position,part)
06    if tool.Ammo.Value > 0 then
07        if not enabled then
08            enabled = true
09            tool.Ammo.Value = tool.Ammo.Value - 1
10 
11            local bullet = Instance.new("Part",game.Workspace)
12            bullet.BrickColor = BrickColor.new("New Yeller")
13            bullet.Transparency = 0
14            bullet.Material = Enum.Material.SmoothPlastic
15            bullet.Anchored = true
View all 53 lines...

Thanks!

0
maybe make a variable of game.Players.LocalPlayer Idrk tbh kingblaze_1000 359 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Problem fixed! All I had to do was delete:

1local tool = script.Parent

in the server script then add the variable "tool" in the local script to the remote event!

Ad

Answer this question