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

How can I improve my player job code?(short)

Code works just want someone's opinion on it or how to improve it. Feel free to say anything.

local BricksLocation = game.Workspace:FindFirstChild('Fixbricks')
local BricksDebounce = {} -- ServerSide Debounce
if BricksLocation then
	for _, brick in pairs(workspace.Fixbricks:GetChildren()) do
		if brick.Name == "fixbrick" and brick:FindFirstChild("ProximityAttachment") then
			local ProximityAttachment = brick:FindFirstChild('ProximityAttachment')
			ProximityAttachment.ProximityPrompt.Triggered:Connect(function(plr)
				local Teams = game:GetService("Teams")
				if plr.Team == Teams.Worker and not BricksDebounce[plr.Name] then
					BricksDebounce[plr.Name] = true
					local reward = GetReward(2)
					ServerDataFolder[plr.Name].leaderstats.Cash.Value = ServerDataFolder[plr.Name].leaderstats.Cash.Value +reward
					brick.ParticleEmitter.Enabled = false
					brick.Sparks:Stop()
					ProximityAttachment.ProximityPrompt.Enabled = false
					wait(20)
					BricksDebounce[plr.Name] = nil
					wait(200)
					brick.ParticleEmitter.Enabled = true
					ProximityAttachment.ProximityPrompt.Enabled = true
					brick.Sparks:Play()
				end
			end)
		end
	end
end

1 answer

✓ Accepted answer

here are some observations:

  1. it’s better to sort your data using player.UserId rather than player.Name
  2. it’s better to use GetService at the beginning of the script rather than nesting them (for readability)

2 comments

0

Gotcha on there first stuff, but I thought the .Triggered is listening so it would work fine without coroutines?

0

you're right, I read this on my phone and I looked real hard but didn't see the connect, lol. sorry.

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