Help to fix script

It’s okay I’m in the Dev forums for a week waiting for an answer 3 hours it’s nothing

1 Like

Put a boolvalue in each player model. Once you touch the part, an function triggers, and if the boolvalue value = false then you set it to true and it gives you the boost. Then for your tool, you can do the same thing, but then for when you do it with the tool.

Please let me know if this was what you needed!

This really burnt my brain. But anyways,

This is what I think I understood, tho the video you showed doesn’t seem to be connected to the boost thingy.

For me the problem 1 seems like a coin collecting system but it gives you strength.

Problem 2 seems to be some sort of bug but only if the boost is applied.

Let’s get to the matter now :

Problem 1 : you are trying to make a system where the player can only touch the part one time, then you can use the solution @Jopio0819 gave.
Other possible Solution(s) for P1 : Else you can use a table putting all the users (UserId) inside the table who’ve touched / Got the boost. Ofcourse you can also disable CanTouch from local side so the plr won’t be able to touch the part again.

Code:

local debounce = false
local _plrsGottenBoostFromPart = {} --// Table that stores plrId for who ever touched the part


script.Parent.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

	if plr ~= nil and debounce == false then
		if table.find(_plrsGottenBoostFromPart, plr.UserId) then return end --// if plrId Is found then stoping the function from going further
		table.insert(_plrsGottenBoostFromPart, plr.UserId) --// Inserting plrId so the next time the plr touches the part he won't get the boost
		
		debounce = true --// setting delay to true for spam issues
		
		plr.Endurance.Value += 1e90 

		wait(1)
		debounce = false
	end
end)


game.Players.PlayerRemoving:Connect(function(plr) --// Removing playerId when player leaves
	
	if table.find(_plrsGottenBoostFromPart, plr.UserId) then --// Checking if playerId is found in the table
		for i, plrId in pairs(_plrsGottenBoostFromPart) do   --// looping through the table to check the index
			if plrId == plr.UserId then
				table.remove(_plrsGottenBoostFromPart, i) --// Removing the playerId according to the set index
			end
		end
	end 
	
end)

Problem 2 : You do not want the players to get the boost when he is using a tool
Possible Solution(s) for P2 : You can just check if the player is using a tool or not and work accordingly.

Code :

if plr.Character:FindFirstChildWhichIsA("BackpackItem") then --// Player is using a tool from his backpack
	--// Your Code Here
end

If this still isn’t right then feel free to tell us more about this so we can help you further more with this matter. :slight_smile:

Create a BoolValue in the player, let’s call it “FixBoost.” After that, if you want to achieve gradual strength increase, you can add a more complex script with checks and strength restoration mechanisms, for example.

local TableAllPlayerDesk = {
	
}
script.Parent.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		print("TochAndPlr")
		if not table.find(TableAllPlayerDesk,player) then
			table.insert(TableAllPlayerDesk,player)
			print("AddTable")
			local FixBoost = player:FindFirstChild("FixBoost")
			while wait(1) do
				local DistTableToPlayer = nil
				if game.Players:FindFirstChild(player.Name) ~= nil then
					DistTableToPlayer = (player.Character:FindFirstChild("HumanoidRootPart").Position - script.Parent.Position).magnitude
				end
				if DistTableToPlayer ~= nil then
					local MaxDist = 15
					print(DistTableToPlayer)
					if DistTableToPlayer <= MaxDist then
						print("GiveStamina")
						player.Endurance.Value += 1e90
						FixBoost.Value = true
					elseif DistTableToPlayer > MaxDist then
						FixBoost.Value = false
						local PositionOnTable = table.find(TableAllPlayerDesk,player)
						table.remove(TableAllPlayerDesk,PositionOnTable)
						print("TableRemove")
						break
					end
				elseif DistTableToPlayer == nil then
					local PositionOnTable = table.find(TableAllPlayerDesk,player)
					table.remove(TableAllPlayerDesk,PositionOnTable)
					break
				end
			end
			print(TableAllPlayerDesk)
		end
	end
end)

Blocking the usage of something can be done simply through a check.

if player:FindFirstChild("FixBoost").Value == false then
	print("No Desk")
end

Certainly, I might be wrong, but this is a good option for checking the distance to determine if the player is standing on the desk.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.