So I’ve been having this issue a lot lately where values that are meant to be inserted into the character duplicate depending on the amount of people in game (if there’s two people it inserts into the character twice, three people three times, so on). I’ve tried multiple different methods to fix this, but I’m not sure if the problem is universal (something else is causing everything to duplicate) or because of a certain way I’m inserting the values.
Although this occurs on multiple different values/scripts, here’s a simple crouch script I made that goes through the issue:
--LOCAL
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
buttondown = true
UIS.InputBegan:Connect(function(input, typing)
if typing then return end
--if character:FindFirstChild("WValue") or character:FindFirstChild("SValue") then return end
if input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down and buttondown == true then
RS.Events.CrouchEvent:FireServer("Activate")
while buttondown == true do
wait()
end
RS.Events.CrouchEvent:FireServer("Release")
buttondown = true
end
end)
UIS.InputEnded:Connect(function(input, typing)
if typing then return end
if input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down then
buttondown = false
end
end)
--SERVER
local RS = game:GetService("ReplicatedStorage")
local buttondown = false
RS.Events.CrouchEvent.OnServerEvent:Connect(function(player, action)
local character = player.Character
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://6676757050"
local track = character.Humanoid:LoadAnimation(anim)
if action == "Release" then
if character:FindFirstChild("Crouch") then
game.Debris:AddItem(character:FindFirstChild("Crouch"), 0)
buttondown = false
end
elseif action == "Activate" then
local crouch = Instance.new("BoolValue", character)
crouch.Name = "Crouch"
buttondown = true
while buttondown == true do
wait()
track:Play()
end
buttondown = false
track:Stop()
print(track.IsPlaying)
game.Debris:AddItem(crouch, 0)
end
end)
The script above works with one person, but when two people are in a server, they’re able to cancel out each other’s crouch due to the overlapping values in the character.
Any insight or assistance will be beneficial! This issue has been messing with my project for days/weeks now and I can’t find a suitable solution.