I tried searching a tutorial on Youtube but all the Videos use a remote event and I dont want that so is there any way I can make a stamina GUI without it?
Script:
--// Services
local UIS = game:GetService("UserInputService") -- To detect when the Shift button are pressed *& released
local TS = game:GetService("TweenService") -- To create a buildup effect for our WalkSpeed
local plr = game.Players.LocalPlayer
local player = game.Players.LocalPlayer
--// Listeners
UIS.InputBegan:Connect(function(key) -- 'key' is the Object 'key' pressed
if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 23}):Play()
-- '2' is the time it takes to reach maximum speed
-- '32' is the maximum speed
end
end)
UIS.InputEnded:Connect(function(key) -- 'key' is the Object 'key' let go of
if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 16}):Play()
-- '2' is the time it takes to reach normal speed
-- '16' is the normal WalkSpeed of a player
end
end)
repeat wait() until player.Character --Wait for the character
local humanoid = player.Character.Humanoid
local staminaframe = script.Parent.Parent
local staminabar = script.Parent
local staminamax = 100
local db = false --Step 3
local stamina = player:WaitForChild("StaminaVal") --Step 1
humanoid.Changed:connect(function()
if not db then
db = true
while humanoid.WalkSpeed > 16 and wait(1) do --Step 2
stamina.Value = stamina.Value - 1
staminabar.Size = UDim2.new(stamina.Value/staminamax,0,1,0)
end
db = false
end
end)
I found this script deep in the forums, the script basically creates a speed buildup effect
well I don’t recommend calling it a name that’s gonna be obvious, If you are trying to prevent exploiters (it will only prevent like 1%, aka the noob ones) Most of them have some sort of “remote spy”
I don’t recommend doing a client sided one because exploiters can just edit the stamina and make it basically infinite. If you do it as server sided they will be able to use the remote event but it wont nessicarilly do anything for the exploiters. they can only use what’s on the client side which does include remote events, if you put a function with arguments available on the remote event, yes they could definitely change their stamina and exploit it somehow depending on where the arguments go, But if you don’t they won’t be able to change anything on the server side and mess with it.
Since Gui’s are parented to the StarterGui & are managed with local scripts & player stats need to be controlled server side otherwise they won’t be reflected server-wide, you’ll need to make use of a RemoteEvent to allow for communication between the player’s Stamina stat & the Stamina Bar UI.
Server sided scripts would run on the server, mostly used to change something that would change (appearance) for all clients. Client/Player sided scripts would be used to change properties of the actual client player and its humanoid and other instances available to the client. The client sided scripts can change the players in the game’s properties but they will not show for everyone else. Rather if it was server sided it would show for everyone.
If you don’t really care about exploiters (which is what the post looks like), don’t bother doing it on the server, you can simply do it on the client.
Didn’t test the code but I think you’d do something like this:
--// Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
--// Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local StaminaBar = script.Parent
local StaminaFrame = StaminaBar.Parent
local MinSize --The size when the stamina is 0
local MaxSize --The size when the stamina is 100
local DefaultSpeed = Humanoid.WalkSpeed
local SprintSpeed = 23
local SprintTween = TweenService:Create(Humanoid, TweenInfo.new(2), {WalkSpeed = SprintSpeed})
local BarDrainTween = TweenService:Create(StaminaBar, TweenInfo.new(2), {Size = MinSize})
local BarRegenTween = TweenService:Create(StaminaBar, TweenInfo.new(5), {Size = MaxSize})
--// Code
UserInputService.InputBegin:Connect(function(Key) --Key was pressed
if Key.KeyCode == Enum.KeyCode.LeftShift or Key.KeyCode == Enum.KeyCode.RightShift then --And key was the sprint key
if StaminaBar.Size == MaxSize then --If you can sprint
SprintTween:Play() --Raise the player speed
BarDrainTween:Play() --Decrese the bar
end
end
end)
UserInputService.InputEnded:Connect(function(Key) --Key stopped being pressed
if Key.KeyCode == Enum.KeyCode.LeftShift or Key.KeyCode == Enum.KeyCode.RightShift then --Player stopped pressing sprint key
Humanoid.WalkSpeed = 16 --Set the speed to default (Make a tween for this if you want).
BarRegenTween:Play() --Regen Tween
end
end)
If it is a client-side anti cheat, it can be removed/disabled by the exploiter. Even if you make some sort of ping system, exploiters can replicate it.
so, for example, starter character scripts are client sided because it changes the humanoid and stuff but what if I put the script in a GUI frame is it still client-sided?
Yes it is still client sided, You can access the same client’s properties as if you were to put it inside of StarterPlayerScripts. But mainly when you put it inside you are mainly only changing the GUI’s contents not using it for the player. I’m not sure that if it’s inside of a gui inherited than it has access to services.
Local scripts are clientside, and normal scripts are serverside. However, local scripts will only run in areas like replicatedfirst, the character instance, and the player instance. starter character scripts just moves the scripts inside of it into the player when the game starts.
Normal scripts will run pretty much anywhere that local scripts cant run.
No, i meant replicatedfirst. replicatedfirst is the first instance/service to be replicated to the client. Im not sure if local scripts run in replicatedstorage, but i think they dont.