What do you think about my EggHunt script?

Basically, what it does is when you walk through the egg, you receive the launcher connected to that egg.

local enabled = true

game.Players.PlayerAdded:Connect(function(p)

script.Parent.Touched:Connect(function()

    if not p.Backpack:FindFirstChild("CreatorLauncher") and not 
p.Character:FindFirstChild("CreatorLauncher") then

        if enabled == true then
        game.ServerStorage.Launchers.CreatorLauncher:Clone().Parent = p.Backpack

        enabled = false
        script.Parent.Transparency = 1

        wait(46)

        enabled = true
        script.Parent.Transparency = 0

        end
    end
end)
end)
8 Likes

what… Do this on the client and give an item on the server, or do it all on the server but create individual cooldowns for each player. This is mentally not ok, but since you seem like a new scripter, it’ll pass.

4 Likes

This is on the server so this will have a cooldown for every 46 seconds or so and if someone has the launcher in their backpack already they cannot claim it again.

4 Likes

Yes, but make debounces on all players.

2 Likes

It does. Thats the point. So then people can’t repeatedly get it.

2 Likes

“enabled” is the debounce. I just called it something else.

2 Likes

What about the transparency? That should only be on the client.

1 Like

Why? It’s supposed to be server sided. And, it works :smiley:

2 Likes

The main purpose of it is to be hard to get.

2 Likes

Check if the hit part is a player, also try using Region3 on client. Region3 is more efficient

I’d recommend just using the touched event because you can get the player from the event using the GetPlayerFromCharacter function. A Region3 would be more reliable.

2 Likes

Why do a overcomplicated solution that would be less secure rather than using a simple, slightly more secure solution? This simple script isn’t going to cause any lag at all using a Touched event on the server.
All OP needs to do is just add a check for if the thing that touched the egg is a player.

(i say slightly more secure because touched events can be manipulated through network ownership, but that’s still a bit more secure than letting every client say “i touched this region!” regardless of network ownership or not)

3 Likes

Isn’t using .Touched already unreliable? Region3 is probably the most reliable since when a part is in a zone, it automatically runs the code if it’s in a loop, on the other hand .Touched is for more beginner scripters because of how simple it is.

It’s not complicated, it’s just basic math. He doesn’t have to use Region3 on the client, he can also use it on the server. Also why would it cause lag?

-- some code by regularwolf since i cant do anything time consuming right now
-- possibly might not work. i haven't used region3 or touched in a while
local rg1 = game.Workspace:WaitForChild("rg1").Position
local rg2 = game.Workspace:WaitForChild("rg2").Position

while wait(.1) do
local region3 = Region3.new(
     Vector3.new(math.min(rg1.X, rg2.X), math.min(rg1.Y, rg2.Y), math.min(rg1.Z, rg2.Z))
     Vector3.new(math.max(rg1.X, rg2.X), math.max(rg1.Y, rg2.Y), math.max(rg1.Z, rg2.Z))
)

local parts = workspace:FindPartInRegion3(region3)

for i,v in pairs(parts) do
   if v and v.Parent and v.Parent.Name == Player.Name then
       -- extra code
   end
end

end

He still has the option to use .Touched because it seems like he’s new to scripting.

3 Likes

From the many times I’ve used the Touched event I’ve found the only unreliable thing related to it is that TouchEnded doesn’t always fire, but TouchEnded isn’t even needed here because it’s a simple egg script. Touched has always worked perfectly fine for me for picking up dropped currency, teleport pads and more.

As for why I think Region3 would lag more, If you used Region3’s instead of the Touched event and had a lot of scripts constantly checking for things in Region3’s, you’d be doing a lot of unneeded processing. It’s always best to go for event-based programming instead of using loops where you don’t need loops.

I would use a Region3 for detecting if a player was in a no-pvp safe zone or something like that, not for detecting if a egg launcher was touched up by a player to give it to them. I don’t see why Region3’s would be used here.

3 Likes

Nice. I really like this. Good Job @Aiden_12114!

1 Like