Iam creating a game like Power simulator, and i created training areas, when player enter on Part i fire BindledEvent (inside workspace), so when that fire my Script on ServerScriptStorage receive the values and start the player training
Part :
local touching = false
local StartTraining = game.Workspace:WaitForChild("StartTraining")
local StopTraining = game.Workspace:WaitForChild("StopTraining")
local module = {}
function module.Get()
return touching
end
function module.Training(player,amount,Part,Stat,Touchings)
touching = Touchings
if touching then
StartTraining:Fire(player,amount,Part,Stat)
else
end
end
return module
ServerScriptService :
--training events--
local AutoTraining = {}
local function increaseStats(Player,Amount,Stat)
while true do
wait(1)
if not AutoTraining[Player.UserId] then return end
ServerData[Player.UserId]["Stats"][""..Stat]["Value"] = ServerData[Player.UserId]["Stats"][""..Stat]["Value"] + 50
print(ServerData[Player.UserId]["Stats"][""..Stat]["Value"])
end
end
local function checkIsTrainingArea(player,Amount,Part,Stat)
print("checkingg")
print(Amount)
local touching = Part:GetTouchingParts()
local ValidPosition = false
for i=1,#touching do
if touching[i] == player.Character.HumanoidRootPart then
ValidPosition = true
break
end
end
if ValidPosition == true then
AutoTraining[player.UserId] = true
increaseStats(player,Amount,Stat)
end
ValidPosition = nil
touching = nil
end
local function stopTrainingF(Player,Part)
local touching = Part:GetTouchingParts()
local ValidPosition = false
for i=1,#touching do
if touching[i] == Player.HumanoidRootPart then
ValidPosition = true
break
end
end
if ValidPosition == true then
AutoTraining[Player.UserId] = false
end
ValidPosition = nil
touching = nil
end
StartTraining.Event:Connect(checkIsTrainingArea)
I Will put more security If Exploiters can fire that, If not i wont, so they can or no ?