Training area system problem

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

I want it so when your in the area and clicking it adds 2 value but when your not in it only one

  1. What is the issue? Include screenshots / videos if possible!

When i click outside of the area it give me one value which is good but when i touch the area without clicking it gives massive number how do i make it so first it checks if touching the area, then if it is when you click add 2 value pretty simple but im stuck im not sure how to do it

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I found nothing so far on this topic

local StrengthStatFolder = script.Parent:WaitForChild("StatsFolder")
local StrengthStat = StrengthStatFolder:WaitForChild("StrengthStat")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local TrainingZone = workspace["Training Zone"]
local Multiplier = TrainingZone.Multiplier


Mouse.Button1Down:Connect(function()
	StrengthStat.Value = StrengthStat.Value + 1
end)


TrainingZone.Touched:Connect(function()
	if not Mouse.Button1Down then return
	else
		StrengthStat.Value = StrengthStat.Value + 2
	end
end)



Use a BoolValue to determine if the player is in the area or not. You can do this by adding it to your Touched event. Don’t forget to add a debounce tho!

im doing it the client ive tried that btw didnt work

Refer to this topic here:

is it possible to use region3 in my case

Sure! I mean its your choice on how you want to script it, as long as it works. You can try and see if it works or use :GetTouchingParts() to check if there’s a HumanoidRootPart like it said in that topic I shared in the previous post.

local Players = game:GetService(“Players”)

local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)

local IncreaseTouch = false

local StrengthStatFolder = script.Parent:WaitForChild(“StatsFolder”)
local StrengthStat = StrengthStatFolder:WaitForChild(“StrengthStat”)

local TrainingZone = workspace[“Training Zone”]
local Multiplier = TrainingZone.Multiplier

Mouse.Button1Down:Connect(function()
local value = IncreaseTouch and 2 or 1

StrengthStat.Value = StrengthStat.Value + value

end)

TrainingZone.Touched:Connect(function(hit, limb)
if IncreaseTouch then return end

local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")

if not humanoid then return end

local player = Players:GetPlayerFromCharacter(character)

if player ~= Player then return end

IncreaseTouch = true

end)

TrainingZone.TouchEnded:Connect(function(hit)
if not IncreaseTouch then return end

local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")

if not humanoid then return end

local player = Players:GetPlayerFromCharacter(character)

if not player == Player then end
-- we know that it is the player that stopped touching it

IncreaseTouch = false

end)

if anyone needs

1 Like