--Sprinting Script
local Player = game:GetService("Players")
local Character = Player.LocalPlayer.Character or Player.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local CharacterInfo = Character:WaitForChild("CharacterInfo")
local CanSprint = CharacterInfo.CanSprint
local Interacting = CharacterInfo.Interacting
local Camera = workspace.CurrentCamera
local PlayerGui = Player.LocalPlayer.PlayerGui
local SprintGui = PlayerGui:WaitForChild("SprintGui")
local GuiService = game:GetService("GuiService")
local BackgroundFrame = SprintGui.BackgroundFrame
local SprintFrame = BackgroundFrame.SprintFrame
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Stamina = 100
local MaxStamina = 100
local Sprinting = false
local OriginalWalkSpeed
local OriginalFieldOfView
RunService.RenderStepped:Connect(function()
SprintFrame.Size = UDim2.new(Stamina/MaxStamina,0,1,0)
end)
UserInputService.InputBegan:Connect(function(Input,Chatting)
if Humanoid.Health > 0 then
if Input.KeyCode == Enum.KeyCode.LeftShift and Chatting == false and CanSprint.Value == true then
local ShowSprintUI
Sprinting = true
OriginalWalkSpeed = Humanoid.WalkSpeed
OriginalFieldOfView = Camera.FieldOfView
Humanoid.WalkSpeed = 32
Camera.FieldOfView = 90
for i,Frames in pairs(SprintGui:GetDescendants()) do
if Frames:IsA("Frame") then
ShowSprintUI = TweenService:Create(Frames,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency = 0})
ShowSprintUI:Play()
end
end
end
end
end)
UserInputService.InputEnded:Connect(function(Input,Chatting)
if Input.KeyCode == Enum.KeyCode.LeftShift and Chatting == false and Sprinting == true then
local HideSprintUI
Sprinting = false
Humanoid.WalkSpeed = OriginalWalkSpeed
Camera.FieldOfView = OriginalFieldOfView
task.wait(3)
for i,Frames in pairs(SprintGui:GetDescendants()) do
if Frames:IsA("Frame") then
HideSprintUI = TweenService:Create(Frames,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency = 1})
HideSprintUI:Play()
if Sprinting == true then
HideSprintUI:Cancel()
end
end
end
end
end)
while task.wait(0.05) do
if Sprinting == true then
Stamina -= 1
if Stamina <= 0 then
Stamina = 0
Humanoid.WalkSpeed = OriginalWalkSpeed
Camera.FieldOfView = OriginalFieldOfView
end
else
Stamina += 1
if Stamina >= MaxStamina then
Stamina = MaxStamina
end
end
end
--Npc Script
local Player = game:GetService('Players')
local Character = Player.LocalPlayer.Character or Player.ChildAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local CharacterInfo = Character:WaitForChild("CharacterInfo")
local NpcFolder = workspace.Npcs
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DialogGui = script.Parent
local TextLabel = DialogGui.TextLabel
local MusicAndSoundFolder = ReplicatedStorage.MusicAndSound
local Sound = MusicAndSoundFolder.Sound
local Typing = Sound.Typing
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
local function ProximityPromptsEnabled(Bool)
for i,Npcs in pairs(NpcFolder.InteractableNpcs:GetChildren()) do
local ProximinityPrompt = Npcs.ProximityPrompt
ProximinityPrompt.Enabled = Bool
end
end
local function CreateDialog(String)
for Index = 1,#String do
Typing:Play()
TextLabel.Text = string.sub(String,1,Index)
task.wait(0.08)
end
end
Player.LocalPlayer.CharacterAdded:Connect(function()
ProximityPromptsEnabled(true)
end)
Player.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
ProximityPromptsEnabled(false)
end)
local NpcList = {
Joe = {
[0] = {"Hey what up pal how's it going?"},
[1] = {"Enjoying the place so far?"}
},
Sarra = {
[0] = "Heya~",
}
}
for i,Npcs in pairs(NpcFolder.InteractableNpcs:GetChildren()) do
local ProximinityPrompt = Npcs.ProximityPrompt
local NpcSettings = Npcs.NpcSettings
local Animations = NpcSettings.Animations
local Idle = Npcs.Humanoid.Animator:LoadAnimation(Animations.Idle)
local Talking = Npcs.Humanoid.Animator:LoadAnimation(Animations.Talking)
local Chats = NpcSettings.Values.Chats
local MaxChats = NpcSettings.Values.MaxChats
Idle:Play()
ProximinityPrompt.Triggered:Connect(function()
local OriginalWalkSpeed = Humanoid.WalkSpeed
local OriginalJumpPower = Humanoid.JumpPower
CharacterInfo.CanSprint.Value = false
CharacterInfo.Interacting.Value = true
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
ProximityPromptsEnabled(false)
StarterGui:SetCore("ResetButtonCallback",false)
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
local OriginalPosition = Npcs.HumanoidRootPart.CFrame
local RotateBackToOriginalPos = TweenService:Create(Npcs.HumanoidRootPart,Info,{CFrame = OriginalPosition})
local LookAt = TweenService:Create(Npcs.HumanoidRootPart,Info,{CFrame = CFrame.lookAt(Npcs.HumanoidRootPart.Position,Vector3.new(HumanoidRootPart.Position.X,Npcs.HumanoidRootPart.Position.Y,HumanoidRootPart.Position.Z))})
LookAt:Play()
LookAt.Completed:Wait()
Idle:Stop()
Talking:Play()
DialogGui.Enabled = true
for Name,Text in pairs(NpcList) do
if Name == Npcs.Name then
MaxChats.Value = #Text
for i,Dialog in pairs(Text[Chats.Value]) do
CreateDialog(Npcs.Name..": "..Dialog)
task.wait(1)
end
end
end
Idle:Play()
Talking:Stop()
DialogGui.Enabled = false
RotateBackToOriginalPos:Play()
RotateBackToOriginalPos.Completed:Wait()
ProximityPromptsEnabled(true)
TextLabel.Text = ""
StarterGui:SetCore("ResetButtonCallback",true)
Humanoid.WalkSpeed = OriginalWalkSpeed
Humanoid.JumpPower = OriginalJumpPower
CharacterInfo.CanSprint.Value = true
CharacterInfo.Interacting.Value = false
if Chats.Value < MaxChats.Value then
Chats.Value += 1
end
end)
end
May I ask is the button there clicking in ScreenGUI? cause if so heres the code
local Button = game.StarterGui:FindFirstChild("Button")
Button.MouseButton1Down:Connect(function()
Local player = game.Players:GetPlayerFromCharacter(Player.Character)
player.Walkspeed = 0
end)
a simple check
if CanSprint then
-- allow them to sprint
else
-- do not allow them
end
Try this
for i,Npcs in pairs(NpcFolder.InteractableNpcs:GetChildren()) do
local ProximinityPrompt = Npcs.ProximityPrompt
local NpcSettings = Npcs.NpcSettings
local Animations = NpcSettings.Animations
local Idle = Npcs.Humanoid.Animator:LoadAnimation(Animations.Idle)
local Talking = Npcs.Humanoid.Animator:LoadAnimation(Animations.Talking)
local Chats = NpcSettings.Values.Chats
local MaxChats = NpcSettings.Values.MaxChats
local OriginalWalkSpeed = Humanoid.WalkSpeed
local OriginalJumpPower = Humanoid.JumpPower
Idle:Play()
ProximinityPrompt.Triggered:Connect(function()
CharacterInfo.CanSprint.Value = false
CharacterInfo.Interacting.Value = true
if CanSprint then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
end
ProximityPromptsEnabled(false)
StarterGui:SetCore("ResetButtonCallback",false)
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
local OriginalPosition = Npcs.HumanoidRootPart.CFrame
local RotateBackToOriginalPos = TweenService:Create(Npcs.HumanoidRootPart,Info,{CFrame = OriginalPosition})
local LookAt = TweenService:Create(Npcs.HumanoidRootPart,Info,{CFrame = CFrame.lookAt(Npcs.HumanoidRootPart.Position,Vector3.new(HumanoidRootPart.Position.X,Npcs.HumanoidRootPart.Position.Y,HumanoidRootPart.Position.Z))})
LookAt:Play()
LookAt.Completed:Wait()
Idle:Stop()
Talking:Play()
DialogGui.Enabled = true
for Name,Text in pairs(NpcList) do
if Name == Npcs.Name then
MaxChats.Value = #Text
for i,Dialog in pairs(Text[Chats.Value]) do
CreateDialog(Npcs.Name..": "..Dialog)
task.wait(1)
end
end
end
Idle:Play()
Talking:Stop()
DialogGui.Enabled = false
RotateBackToOriginalPos:Play()
RotateBackToOriginalPos.Completed:Wait()
ProximityPromptsEnabled(true)
TextLabel.Text = ""
StarterGui:SetCore("ResetButtonCallback",true)
Humanoid.WalkSpeed = OriginalWalkSpeed
Humanoid.JumpPower = OriginalJumpPower
CharacterInfo.CanSprint.Value = true
CharacterInfo.Interacting.Value = false
if Chats.Value < MaxChats.Value then
Chats.Value += 1
end
end)
end
u make an if statement to check.
Wait are you talking about Proximity prompt? Since I don’t remember adding a button unless I added it by mistake.
This works but the problem is that the player sprint bar still goes down which I don’t want and also when the player let’s go of left shift there able to walk again.
if you have a stop sprinting function you can fire that just immediately after the player interacts with npc