Hey so as the title says i need to fix this script i know it is a little bit messy and its a big one but i really need help, basically everytime when you shoot/fart it - 1 ammo but when some players join like lets say its 4 total players it will - 4 ammo not 1 for the player why is it that.
Local Script
local remoteEvent = game.ReplicatedStorage:WaitForChild("FartEvent")
local input = game:GetService("UserInputService")
local debounce = false
local equiped = false
local ui = script.Parent:WaitForChild("FartUi"):Clone()
local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local ammoleft = plr:WaitForChild("Farts")
local rolls = plr:WaitForChild("Rolls")
local reloading = script.Parent:WaitForChild("Reloading")
script.Parent.Equipped:Connect(function()
equiped = true
ui.Parent = plrGui
end)
script.Parent.Unequipped:Connect(function()
equiped = false
ui.Parent = nil
end)
local function updateGui()
if not reloading.Value then
ui:WaitForChild("Bg").MainFarts.HowMuchLeft.Text = ammoleft.Value
ui:WaitForChild("Bg").MainFarts.texthowleft.Text = "X" .. rolls.Value
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 10"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 9"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 8"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 7"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 6"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 5"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 4"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 3"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 2"
wait(1)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 1"
wait(0.5)
ui:WaitForChild("Timer").Text = "Butt Fart Timer: 0"
ui:WaitForChild("Bg").MainFarts.HowMuchLeft.Text = "Reloading..."
wait(1)
ui:WaitForChild("Bg").MainFarts.HowMuchLeft.Text = ammoleft.Value
end
end
local function toggleReload()
if reloading.Value then
ui:WaitForChild("Bg").MainFarts.HowMuchLeft.Text = "Reloading..."
else
ui:WaitForChild("Bg").MainFarts.HowMuchLeft.Text = ammoleft.Value
ui:WaitForChild("Bg").MainFarts.texthowleft.Text = "X" .. rolls.Value
end
updateGui()
end
input.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if equiped == true then
if input.KeyCode == Enum.KeyCode.F then
if not debounce then
debounce = true
remoteEvent:FireServer(plr)
wait(10)
debounce = false
end
end
end
end)
ammoleft:GetPropertyChangedSignal("Value"):Connect(updateGui)
rolls:GetPropertyChangedSignal("Value"):Connect(updateGui)
reloading:GetPropertyChangedSignal("Value"):Connect(toggleReload)
updateGui()
Server Script
local remoteEvent = game.ReplicatedStorage:WaitForChild("FartEvent")
local debris = game:GetService("Debris")
local CropEvent = game.ReplicatedStorage.Crop
local sound = script.Parent.FartSound
local debounce = false
local ammoleft = 0
local rolls = 0
local reloading = script.Parent.Parent:WaitForChild("Reloading")
local maxAmmo = 10
local function reload()
if reloading.Value then return end
if rolls.Value > 0 then
rolls.Value -= 1
reloading.Value = true
task.wait(5)
ammoleft.Value = maxAmmo
reloading.Value = false
else
return
end
end
remoteEvent.OnServerEvent:Connect(function(player)
if ammoleft.Value > 0 and not reloading.Value then
else
reload()
end
end)
remoteEvent.OnServerEvent:Connect(function(player)
ammoleft = player:WaitForChild("Farts")
rolls = player:WaitForChild("Rolls")
if ammoleft.Value > 0 and not reloading.Value then
if not debounce then
debounce = true
local hrp = player.Character:WaitForChild("HumanoidRootPart")
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {player.Character}
params.IgnoreWater = true
local ray = workspace:Raycast(hrp.Position, -hrp.CFrame.LookVector*10,params)
if ray and ray.Instance then
local playerHit = game.Players:GetPlayerFromCharacter(ray.Instance.Parent)
if playerHit then
playerHit.leadersta.Points.Value -= 5
player.leadersta.Points.Value += 5
playerHit.Character.Humanoid.Health = 0
end
end
if ray and ray.Instance and ray.Instance.Parent:FindFirstChild("NPC") then
player.leadersta.Points.Value += 10
end
local Fart = game.ReplicatedStorage.Fart:Clone()
Fart.Parent = game.Workspace
Fart.Name = "FartClone"
Fart.CFrame = player.Character:WaitForChild("LowerTorso").CFrame
Fart.fartp:Emit(5)
sound:Play()
ammoleft.Value = ammoleft.Value - 1
debris:AddItem(Fart,2.5)
wait(2.5)
debounce = false
end
end
end)
