Hello everyone, I’m currently having issues with a RemoteEvent. The event seems to fire just fine the first time it’s fired, then it fires twice, then three times, etc. I only want it to fire once every time and I’ve searched everywhere in hope of finding a solution to this problem, but it seems I can’t. Some help would be appreciated, thanks!
Basically, whenever you activate a tool a GUI appears with a confirm and deny button. Once the UI opens it takes the tool away from you until you choose an option and restrains your movement. Whenever you click the Deny Button, it gives you back your tool and disables the UI. This all works fine, except for every time you re-open the tool and click the deny button again, the remote event fires one more each time. I’m not sure how to combat this.
Local Script in Tool:
local player = game:WaitForChild("Players").LocalPlayer
local fruit = script.Parent
local warningUI = player.PlayerGui:WaitForChild("FruitWarning")
local reFolder = game:WaitForChild("ReplicatedStorage"):WaitForChild("FruitEvents")
local beginMovement = reFolder:WaitForChild("BeginMovement")
local stopMovement = reFolder:WaitForChild("StopMovement")
local giveto = reFolder:WaitForChild('GiveTo')
local takeaway = reFolder:WaitForChild("TakeAway")
function consume()
print("Fruit Consumed")
-- Consuming Fruit
takeaway:FireServer(fruit)
warningUI:WaitForChild("Frame"):WaitForChild("Front").Text = "Are you sure you would like to consume the Air Fruit?"
fruit.Parent = game:WaitForChild("ReplicatedStorage")
warningUI:WaitForChild("Frame").Visible = true
stopMovement:FireServer(player)
-- Accepts Fruit
warningUI:WaitForChild("Frame"):WaitForChild("Confirm").Activated:Connect(function()
warningUI:WaitForChild("Frame").Visible = false
beginMovement:FireServer(player)
-- Data Store for Fruit Add
game:WaitForChild("ReplicatedStorage"):WaitForChild("FruitEvents"):WaitForChild("AcceptFruit"):FireServer(player, fruit)
fruit:Destroy()
return
end)
-- Denies Fruit
warningUI:WaitForChild("Frame"):WaitForChild("DENY").Activated:Connect(function()
giveto:FireServer(fruit)
warningUI:WaitForChild("Frame").Visible = false
beginMovement:FireServer(player)
end)
end
fruit.Activated:Connect(consume)
Server script in ServerScriptService:
local rs = game.ReplicatedStorage
rs.FruitEvents.StopMovement.OnServerEvent:Connect(function(player)
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0
end)
rs.FruitEvents.BeginMovement.OnServerEvent:Connect(function(player)
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpPower = 50
end)
rs.FruitEvents.TakeAway.OnServerEvent:Connect(function(player, fruit)
fruit.Parent = game.ServerStorage
end)
-- this fires more and more each time
rs.FruitEvents.GiveTo.OnServerEvent:Connect(function(player, fruit)
print("Event Received")
fruit.Parent = player.Backpack
end)