My Problem is that when i spawn in, it spawns the chests, then I go up to the first one and it shows the gui. But when I walk Up To The Second Chest it does not show the gui for some reason but i can go back to the first chest and it will show the gui again.
First Chest: https://gyazo.com/ff7057c2c19c30ec3d8df1f56ee9038a
Second Chest: https://gyazo.com/6d4603721e8f8143cd7eede6d7bd78e1
Explorer Images: Chest Location Gui Location
Script:
01 | local Chests = workspace.Chests |
02 | local Range = 10 |
03 | local P = game.Players.LocalPlayer |
04 | local C = P.Character or P.CharacterAdded:Wait() |
05 | local Hb = game:GetService( "RunService" ).Heartbeat |
06 |
07 | function Check() |
08 | for i,v in pairs (Chests:GetChildren()) do |
09 | if (v.Hitbox.Position - C.PrimaryPart.Position).Magnitude < = Range and not v.Openers:FindFirstChild(P.Name) then |
10 | local Pos = workspace.CurrentCamera:WorldToScreenPoint(v.Hitbox.Position) |
11 | script.Parent.Open.Position = UDim 2. new( 0 ,Pos.X, 0 ,Pos.Y, 0 ) |
12 | script.Parent.Open.Visible = true |
13 | else |
14 | if script.Parent.Open.Visible then |
15 | script.Parent.Open.Visible = false |
Use ContextActionService to bind an action to the 'E' key when the player gets close to the chest, then use ContextActionService: SetImage to have the GUI appear (https://developer.roblox.com/en-us/api-reference/function/ContextActionService/SetImage), then when the player is too far from the chest, unbind the action from the key and rebind it again when the player is close enough to a chest. Just use remote events when the player presses the 'E' from a local script and then fire the server. I hope it helps!