Hi there!
Currently, I’ve been developing a sort of gun “buying” system except without the buying part and just pressing the button to get the gun.
The whole point is so that a player can use the proximity prompt to “talk” to the NPC, have the camera focus on the NPC and select and gun then press Exit.
Currently, the code when pressing the Exit button (BackButton) is not closing, merely closing the Gui and not reverting back to the player’s camera.
Here are the codes (there are no errors)
Camera Mover/ NPC Focuser Code:
local CurrentCamera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")
local Prompt = game.Workspace.NPCRSIX.ProximityPrompt
local BackButton = game.StarterGui.ScreenGui.BackButton
CurrentCamera.CameraType = Enum.CameraType.Scriptable
local Animation = TweenService:Create(CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0), {["CFrame"] = workspace.REODPART.CFrame})
TEST = false
Prompt.Triggered:Connect(function(player)
task.wait(0.1)
Prompt.Enabled = false
Animation:Play()
CurrentCamera.HeadLocked = false
CurrentCamera.CameraType = Enum.CameraType.Fixed
player.Character:WaitForChild("HumanoidRootPart").Anchored = true
Animation.Completed:Wait()
runService:BindToRenderStep("NPCfocus", Enum.RenderPriority.Camera.Value + 1, function()
CurrentCamera.CFrame = CFrame.new(workspace.REODPART.Position, game:GetService("Workspace").FOCUSPART.Position)
end)
BackButton.MouseButton1Click:Connect(function(player)
runService:UnbindFromRenderStep("NPCfocus")
player.Character:WaitForChild("HumanoidRootPart").Anchored = false
Animation:Stop()
Prompt.Enabled = true
CurrentCamera.HeadLocked = true
CurrentCamera.CameraType = Enum.CameraType.Scriptable
end)
end)
Gui Code:
local Prompt = game.Workspace.NPCRSIX.ProximityPrompt
local ScreenGui = game.Players.LocalPlayer.PlayerGui.ScreenGui
local Button = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton
local BackButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.BackButton
Prompt.Triggered:Connect(function()
ScreenGui.Enabled = true
end)
Button.MouseButton1Click:Connect(function()
local plr = game.Players.LocalPlayer
local backpack = plr:WaitForChild('Backpack')
local Shotgun = game:GetService('ReplicatedStorage'):WaitForChild('Shotgun')
Shotgun:Clone().Parent = backpack
end)
BackButton.MouseButton1Click:Connect(function()
ScreenGui.Enabled = false
end)
I think I may need to add a piece to the Gui code so that it talks to the NPC code and verifies that the player is closing the “shop”.
I’ve tried putting the subject back to the humanoid but I am not fully sure I did it correctly.
Any help would be much appreciated as these are issues I am not sure how to solve.
Check comments for updated Gui/NPC codes