Simulator system not working (no errors?)

I made a training system where when you are in an area and click a GUI button you get strength based on what area you are on (CurrentBag) but its not working with 0 errors. I don’t see anything wrong.

Here’s my scripts maybe you can find something I skipped over:

Server Script

game.Players.PlayerAdded:Connect(function(plr)
	local de = Instance.new("BoolValue")
	de.Name = "de"
	de.Parent = plr
	de.Value = false
	
	local CurrentBag = Instance.new("IntValue")
	CurrentBag.Name = "CurrentBag"
	CurrentBag.Parent = plr
	
	local Char = plr.Character or plr.CharacterAdded:Wait()
	local CheckerPart = Instance.new("Part")
	CheckerPart.Name = "CheckerPart"
	CheckerPart.Parent = Char.HumanoidRootPart
	CheckerPart.Size = Vector3.new(0.1, 0.1, 0.1)
	CheckerPart.Position = Char.HumanoidRootPart.Position
	CheckerPart.Anchored = false
	CheckerPart.Transparency = 1
	CheckerPart.CanCollide = false
	local CheckerPartWeld = Instance.new("WeldConstraint")
	CheckerPartWeld.Name = "CheckerPartWeld"
	CheckerPartWeld.Parent = Char.HumanoidRootPart.CheckerPart
	CheckerPartWeld.Part0 = Char.HumanoidRootPart.CheckerPart
	CheckerPartWeld.Part1 = Char.HumanoidRootPart
	
	while wait(0.1) do
		CheckerPart.Touched:Connect(function(hit)
			if hit == game.Workspace["1"] then
				plr.CurrentBag.Value = 1
			elseif hit == game.Workspace["2"] then
				plr.CurrentBag.Value = 2
			elseif hit == game.Workspace["3"] then
				plr.CurrentBag.Value = 3
			elseif hit == game.Workspace["4"] then
				plr.CurrentBag.Value = 4
			elseif hit == game.Workspace["5"] then
				plr.CurrentBag.Value = 5
			end
		end)
		CheckerPart.TouchEnded:Connect(function(hit)
			if hit == game.Workspace["1"] then
				plr.CurrentBag.Value = 0
			elseif hit == game.Workspace["2"] then
				plr.CurrentBag.Value = 0
			elseif hit == game.Workspace["3"] then
				plr.CurrentBag.Value = 0
			elseif hit == game.Workspace["4"] then
				plr.CurrentBag.Value = 0
			elseif hit == game.Workspace["5"] then
				plr.CurrentBag.Value = 0
			end
		end)
	end
end)

Server Script

local rs = game:GetService("ReplicatedStorage")
local BagEvents = rs:WaitForChild("BagEvents")
local BagEvent1 = BagEvents:WaitForChild("1")
local BagEvent2 = BagEvents:WaitForChild("2")
local BagEvent3 = BagEvents:WaitForChild("3")
local BagEvent4 = BagEvents:WaitForChild("4")
local BagEvent5 = BagEvents:WaitForChild("5")

BagEvent1.OnServerEvent:Connect(function(player)
	if player.de == false then
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1
		player.de = true
		wait(1)
		player.de = false
	end
end)
BagEvent2.OnServerEvent:Connect(function(player)
	if player.de == false and player.leaderstats.Strength.Value >= 20 then
		player.de = true
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 5
		wait(0.1)
		player.de = false
	end
end)
BagEvent3.OnServerEvent:Connect(function(player)
	if player.de == false and player.leaderstats.Strength.Value >= 100 then
		player.de = true
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 20
		wait(0.1)
		player.de = false
	end
end)
BagEvent4.OnServerEvent:Connect(function(player)
	if player.de == false and player.leaderstats.Strength.Value >= 500 then
		player.de = true
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 50
		wait(0.1)
		player.de = false
	end
end)
BagEvent5.OnServerEvent:Connect(function(player)
	if player.de == false and player.leaderstats.Strength.Value >= 2500 then
		player.de = true
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 90
		wait(0.1)
		player.de = false
	end
end)

Local Script

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local rs = game:GetService("ReplicatedStorage")
local BagEvents = rs:WaitForChild("BagEvents")
local BagEvent1 = BagEvents:WaitForChild("1")
local BagEvent2 = BagEvents:WaitForChild("2")
local BagEvent3 = BagEvents:WaitForChild("3")
local BagEvent4 = BagEvents:WaitForChild("4")
local BagEvent5 = BagEvents:WaitForChild("5")

script.Parent.MouseButton1Up:Connect(function()
	if player.CurrentBag.Value == 1 then
		BagEvent1:FireServer(player)
	elseif player.CurrentBag.Value == 2 then
		BagEvent2:FireServer(player)
	elseif player.CurrentBag.Value == 3 then
		BagEvent3:FireServer(player)
	elseif player.CurrentBag.Value == 4 then
		BagEvent4:FireServer(player)
	elseif player.CurrentBag.Value == 5 then
		BagEvent5:FireServer(player)
	end
end)

When I got in the area and click the strength doesnt change at all
(The CurrentBag is the area because its a boxing game)

1 Like

why exactly do you have 5 separate “BagEvents”?

1 Like

Possible problems:

  1. You’re running a while loop for each player that joins which is adding a Touched event to the parts every 0.1 seconds, so that’s 10 events per second, per part. So 50 events total per second, per player. Even if you fix the current problem your severs are going to crash ASAP with this current setup.) You only need to connect it once. This may be part of the issue

  2. TouchEnded and Touched aren’t always reliable in terms of detection and may be causing some unintended behavior in terms of detecting what CurrentBag you’re at.

  3. Make sure your TextButton.Active = true
    3.1 Consider using .Activated with the ContextActionService

  4. Your remotes may not be firing for whatever reason - hard to say with the current info

Troubleshooting:

  1. Take out your while loop.

  2. Try adding a print statement / some type of check on the server script to confirm the remote is actually firing to the server.

  3. Double check your ‘CurrentBag’ value in studio test mode to make sure your values are updating as you intended.

2 Likes

For each “area”, they all give deferent amounts and need deferent requirements

1 Like

Thanks so much for the possible solution, I will try this later tonight and let you know the result.

1 Like

It seems like the remote events are not firing, how would I fix this?

1 Like