So I have these two local scripts that manage package drop-offs for my delivery sim, problem is the location is randomized doors with street names and idk how to define which door aka (street.name) the touch function needs to be watching for, trying to avoid remoteevents if possible
Address Randomizer
1 | while wait( 60 ) do |
2 | local Folder = game.Workspace.Folder:GetChildren() |
3 | local Street = Folder [ math.random( 1 , #Folder) ] |
4 | plr.PlayerGui.Address.Text = "New Order: Deliver to " ..Street.Name |
5 | end |
OnTouch Front Door
1 | local part = ???? |
2 | local function onTouched(part) |
3 | --Do stuff when player touches 'Street' from script above |
4 | end |
5 | part.Touched:Connect(onTouched) |
I would name all of the doors the same thing such as "DelieveryDoor" or something, and then put a string inside of the door with the info you need. Then you could do this:
01 | while wait( 60 ) do |
02 | local Folder = game.Workspace.Folder:GetChildren() |
03 | local Street = Folder [ math.random( 1 , #Folder) ] |
04 | plr.PlayerGui.Address.Text = "New Order: Deliver to " ..Street.Name |
05 | end |
06 |
07 | for i, v in pairs (game.Workspace:GetChildren()) do |
08 | if v.Name = = "DelieveryDoor" then |
09 | local function onTouched(v) |
10 | if v.StringValue.Value = = Street.Name then |
11 | --Delievered! |
12 | end |
13 | end |
14 | v.Touched:Connect(onTouched) |
15 | end |
16 | end |