Part only works for one player!

So I made a part that if you stand on it it will go up and down this is in a localscript in the player so every player can make the part go up and down, but for some reason when one player is standing on the part and is making it go up and down the other one cant even if its a local script only one player can use it a time can some help me please?

local player = game:GetService("Players").LocalPlayer
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent

sendSound.OnClientEvent:Connect(function(obj)
	if typeof(obj) == "Instance" and obj:IsA("Part") then
		obj.Position = Vector3.new(obj.Position.X, obj.Position.Y - 0.25, obj.Position.Z)
		
		obj.InSound:Play()

		local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
		local cooldown = 1 - secondOff

		wait(cooldown)

		obj.Position = Vector3.new(obj.Position.X, obj.Position.Y + 0.25, obj.Position.Z)
		
		obj.OutSound:Play()
	end
end)
10 Likes

Can I also see the server-side script that fires ButtonSoundRemoteEvent?

7 Likes

I know, but I kinda need in the serverscript a diffrent debounce for every player after they touch the part do you know how to?

7 Likes

Each player has a different debounce when touching the part? Ok but I will also need to current script

6 Likes

How much debounce time you got on your touch function in server script?

5 Likes

script:

local sendChance = game:GetService("ReplicatedStorage").RemoteEvents.SendChanceRemoteEvent
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent

local obj = script.Parent

obj.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		if game:GetService("Players"):GetPlayerFromCharacter(character) then
			local player = game:GetService("Players"):GetPlayerFromCharacter(character)
				
			local Debounces = {}
			
			if Debounces[player] == false or Debounces[player] == nil then
				Debounces[player] = false;
			end

			if Debounces[player] == false then 
				Debounces[player] = true;

				sendSound:FireClient(player, obj)

				local luckUpgrades = player.Values.LuckUpgrades.Value * 5
				local luck = luckUpgrades / 100 + 1

				local amountSteps = 2

				if player.Values.Steps.Value > 0 then
					for count = 1,player.Values.Steps.Value,1 do
						amountSteps *= 2.3
					end
				end

				amountSteps /= luck
				print(amountSteps)

				amountSteps = math.floor(amountSteps)
				print(amountSteps)

				if amountSteps < 1 then
					amountSteps = 1
				end

				local randomNumber = math.random(1,amountSteps)

				if randomNumber == 1 then
					player.Values.Steps.Value += 1
					local newChance = 2

					for count = 1,player.Values.Steps.Value,1 do
						newChance *= 2.3
					end

					newChance /= luck

					newChance = math.floor(newChance)

					if newChance < 1 then
						newChance = 1
					end
					sendChance:FireClient(player, newChance)
				elseif randomNumber > 1 then

					local chance = 2 / luck
					local newChance = math.floor(chance)

					if newChance < 1 then
						newChance = 1
					end

					sendChance:FireClient(player, newChance)

					local oldSteps = player.Values.Steps.Value
					player.Values.Steps.Value = 0
					local money = 1
					if oldSteps ~= 0 then
						for count = 1,oldSteps,1 do
							money *= 6.3
						end
						money = math.floor(money)

						local moneyMultiplier = player.Values.MoneyUpgrades.Value * 0.20 + 1

						player.leaderstats.Money.Value += money * moneyMultiplier
					end
				end

				sendSound:FireClient(player, obj)

				local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
				local cooldown = 1 - secondOff

				wait(cooldown)
				
				Debounces[player] = false;
			end
		end
	end
end)
3 Likes

that depends on how much they upgraded it but it should be 1 second

3 Likes

Maybe try this:

local sendChance = game:GetService("ReplicatedStorage").RemoteEvents.SendChanceRemoteEvent
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent
local Players = game:GetService("Players")

local obj = script.Parent
local Debounces = {}

obj.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = Players[hit.Parent.Name]
		

		if Debounces[player] == false or Debounces[player] == nil then
			Debounces[player] = false;
		end

		if Debounces[player] == false then 
			Debounces[player] = true;

			sendSound:FireClient(player, obj)

			local luckUpgrades = player.Values.LuckUpgrades.Value * 5
			local luck = luckUpgrades / 100 + 1

			local amountSteps = 2

			if player.Values.Steps.Value > 0 then
				for count = 1,player.Values.Steps.Value,1 do
					amountSteps *= 2.3
				end
			end

			amountSteps /= luck
			print(amountSteps)

			amountSteps = math.floor(amountSteps)
			print(amountSteps)

			if amountSteps < 1 then
				amountSteps = 1
			end

			local randomNumber = math.random(1,amountSteps)

			if randomNumber == 1 then
				player.Values.Steps.Value += 1
				local newChance = 2

				for count = 1,player.Values.Steps.Value,1 do
					newChance *= 2.3
				end

				newChance /= luck

				newChance = math.floor(newChance)

				if newChance < 1 then
					newChance = 1
				end
				sendChance:FireClient(player, newChance)
			elseif randomNumber > 1 then

				local chance = 2 / luck
				local newChance = math.floor(chance)

				if newChance < 1 then
					newChance = 1
				end

				sendChance:FireClient(player, newChance)

				local oldSteps = player.Values.Steps.Value
				player.Values.Steps.Value = 0
				local money = 1
				if oldSteps ~= 0 then
					for count = 1,oldSteps,1 do
						money *= 6.3
					end
					money = math.floor(money)

					local moneyMultiplier = player.Values.MoneyUpgrades.Value * 0.20 + 1

					player.leaderstats.Money.Value += money * moneyMultiplier
				end
			end

			sendSound:FireClient(player, obj)

			local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
			local cooldown = 1 - secondOff

			task.wait(cooldown)

			Debounces[player] = false;
		end
	end
end)
2 Likes

It works with the debounce but now the whole script with like giving coins works for only one player at a time

2 Likes

hmm, maybe you can try to add print before/ after the giving coins thing and tell me the output? Btw, I removed some lines which were useless

local sendChance = game:GetService("ReplicatedStorage").RemoteEvents.SendChanceRemoteEvent
local sendSound = game:GetService("ReplicatedStorage").RemoteEvents.ButtonSoundRemoteEvent
local Players = game:GetService("Players")

local obj = script.Parent
local Debounces = {}

obj.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = Players[hit.Parent.Name]
		
		if Debounces[player] == false or Debounces[player] == nil then
			Debounces[player] = true

			sendSound:FireClient(player, obj)

			local luckUpgrades = player.Values.LuckUpgrades.Value * 5
			local luck = luckUpgrades / 100 + 1

			local amountSteps = 2

			if player.Values.Steps.Value > 0 then
				for count = 1,player.Values.Steps.Value,1 do
					amountSteps *= 2.3
				end
			end

			amountSteps /= luck
			print(amountSteps)

			amountSteps = math.floor(amountSteps)
			print(amountSteps)

			if amountSteps < 1 then
				amountSteps = 1
			end

			local randomNumber = math.random(1, amountSteps)

			if randomNumber == 1 then
				player.Values.Steps.Value += 1
				local newChance = 2

				for count = 1,player.Values.Steps.Value,1 do
					newChance *= 2.3
				end

				newChance /= luck

				newChance = math.floor(newChance)

				if newChance < 1 then
					newChance = 1
				end
				
				sendChance:FireClient(player, newChance)
			elseif randomNumber > 1 then

				local chance = 2 / luck
				local newChance = math.floor(chance)

				if newChance < 1 then
					newChance = 1
				end

				sendChance:FireClient(player, newChance)

				local oldSteps = player.Values.Steps.Value
				player.Values.Steps.Value = 0
				local money = 1
				if oldSteps ~= 0 then
					for count = 1,oldSteps,1 do
						money *= 6.3
					end
					money = math.floor(money)

					local moneyMultiplier = player.Values.MoneyUpgrades.Value * 0.20 + 1

					player.leaderstats.Money.Value += money * moneyMultiplier
				end
			end

			sendSound:FireClient(player, obj)

			local secondOff = 0.02 * player.Values.CooldownUpgrades.Value
			local cooldown = 1 - secondOff

			task.wait(cooldown)

			Debounces[player] = false;
		end
	end
end)
3 Likes

no but it skips it bacause the other player taps I want them to have likje an own script but not a local script

3 Likes

Try removing .LocalPlayer at the end of line 1 (I think when you refer to local player (at the end of line1 ) It is reffering to the client and/or trying putting it into a normal script.

3 Likes

Local script only works for the player… meaning ANYTHING made within a local script only the player SEES, HEARS, TOUCHES, ETC. You’re going to need to change it to a server/normal script.

3 Likes