Hi, Ive implemented a script into my game kindly provided by an okeanskiy tutorial, however there is a confliction with my game in regards to the game having a lobby, then teleporting players into the map, as the stamina script works in the lobby but when players are teleported into the selected map the script no longer functions.
This is the script:
local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
repeat wait() until players.LocalPlayer.Character
local character = players.LocalPlayer.Character
local maxStamina = 250
local staminaRegen = 1
local staminaCost = 5
local sprintSpeed = 24
local walkSpeed = 16
local currentStamina = maxStamina
-- Update Stamina GUI
function updateGui(current, max)
if character.Humanoid.Health <= 0 then
players.LocalPlayer.PlayerGui.Stamina.Enabled = false
end
players.LocalPlayer.PlayerGui.Stamina.Bar.Size = UDim2.new((current / max)* 0.2, 0,0.05, 0)
end
-- Sprint Key Pressed
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if currentStamina >= staminaCost and character.Humanoid.MoveDirection.Magnitude > 0 then
character.Humanoid.WalkSpeed = sprintSpeed
end
end
end)
-- Sprint Key Released
userInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
character.Humanoid.WalkSpeed = walkSpeed
end
end)
runService.Heartbeat:Connect(function()
if character.Humanoid.WalkSpeed == sprintSpeed then
if currentStamina >= staminaCost and character.Humanoid.MoveDirection.Magnitude > 0 then
currentStamina = currentStamina - staminaCost
else
character.Humanoid.WalkSpeed = walkSpeed
end
else
if currentStamina < maxStamina then
currentStamina = currentStamina + staminaRegen
elseif currentStamina > maxStamina then
currentStamina = maxStamina
end
end
updateGui(currentStamina, maxStamina)
end)
When the lobby counts down, the map is chosen, and the players teleport into the map. I attempted a line of code before the current ‘repeat’ line saying something like:
repeat wait() until workspace:FindFirstChild("Map")
(When the chosen map pops into the workspace for the players to tp to) However this didnt work. Anyone have any ideas on how this can conveniently be adjusted to activate the stamina script only when in the map (or both lobby and map for that matter?)
To note, I have value tags which players are assigned to when tped into the map, and also individual teams (which both can be called possibly if that helps, and also with the map getting added into the workspace when the players are about to tp in)
hope this makes sense
thanks