Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I have made a job system, but I get an issue. How can I fix this?

So I made a job system, where you get a mop and have to touch dirt parts. I have also made it that the dirt parts respawn after a while. The problem is that only one person can work at a time. I mean the first person that joined, only he can work. I don't know how to fix this.

I have a folder in workspace and in them are all the dirt parts. In the parts are some scripts. This is the code:

local TweenService = game:GetService("TweenService")
local spill = script.Parent

local goal = {}
goal.Size= spill.Size - Vector3.new(0,5,5)

local tweenInfo = TweenInfo.new(6)

local tween = TweenService:Create(spill,tweenInfo, goal)

local activated = false

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		local humanoid = chr:WaitForChild("Humanoid")

		spill.Touched:Connect(function(hit)
			if hit.Parent.Name == "Mop" then
				if activated == false then
					activated = true
					if spill.Transparency == 0 then
						tween:Play()

						humanoid.WalkSpeed = 0
						wait(6.5)
						humanoid.WalkSpeed = 16						
						spill.Transparency = 1
						spill.Size = Vector3.new(0.128, 3.85, 4.85)
						plr.leaderstats.Salary.Value += math.random(1,5)
					end
					activated = false
				end
			end
		end)
	end)
end)

I made a part if you touch it then you get the money.


game.Players.PlayerAdded:Connect(function(plr)
	
script.Parent.Touched:Connect(function()
		local Tool = plr.Backpack:FindFirstChild("Mop")  or plr.Character:FindFirstChild("Mop")
		
		plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + plr.leaderstats.Salary.Value
		plr.leaderstats.Salary.Value = 0

		if Tool then
			print("Player is holding a mop")
			Tool:Destroy()
		end
	end)
end)

I also made a dialogue so you can talk to a person. Then he gives you.

I have a folder in ReplicatedStorage and in the folder are two RemoteEvents called DialogueVisibleEvent and ToolGiverEvent. I also have the mop tool in ReplicatedStorage

In ServerScriptService, I have three scripts, A leaderstats, a script that makes the dirt parts respawn and a script that gives the player a mop.

This is the dirt part respawn script:

local spills = game.Workspace.Spills:GetChildren()

while true do
	wait(math.random(3,5))
	local randomSpill = spills[math.random(1, #spills)]
	randomSpill.Transparency = 0
end

And lastly the tool giver script

local mopEvent = game.ReplicatedStorage.Events.ToolGiverEvent

	mopEvent.OnServerEvent:Connect(function(plr, tool)
	local toolClone = tool:Clone()
	toolClone.Parent = plr.Backpack
end)

Where in the script did I write wrong? How can I make it so that more players can work? I appreciate if you help me :)

2 comments

0

Can you be more specific in what is the problem, what doesnt work and what does: can the player use the mop but cant clean up the dirt parts or does the player not receive a mop? or the mop doesnt work

0

If another person starts to mop then his walkspeed won't change and he wont get money. Only the first person that joins, that person can only mop

1 answer

I had some problems like this in past, for me the fix was that i needed to add something like :

if plr.Character ~= nil then
-- proceed
end

I personally would make an boolean value called 'hasJob' or something, and if he has the job then only he can work , if hasJob == false then the player can`t work. You added a playerAdded event and used the argument 'plr' which gets every player in the server, not a certain player.

2 comments

0

Should I make a bool inside of the script or like a boolean value outside of the script?

0

You could make the boolean inside the leaderstats using a playerAdded event, so when player join all get that certain boolean value, and then you can proceed with a data save for that boolean value, sorry for answering too late.

This discussion is preserved as it was. New answers, comments, and votes are closed.