Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't i change the IntValue in StarterGui?

Basically a server script that reduces the stamina when the event has been called. I don't know why but the IntValue inside the StaminaGui doesn't change.

--//Services
local replicatedStorage = game:GetService('ReplicatedStorage')
local gui = game:GetService('StarterGui')

--//Variables
local rollEvent = replicatedStorage:WaitForChild('RollEvent')
local stamina = gui:WaitForChild('StaminaGui'):WaitForChild('Stamina')

--//OnServerEvent
rollEvent.OnServerEvent:Connect(function(player)
	stamina.Value = stamina.Value - 25 -- reduce stamina
end)

1 comment

0

you're changing it in startergui, which means you wont see the change until the character respawns

1 answer

✓ Accepted answer

Once you "Start up" the game it is no longer in StarterGui yet it is in PlayerGui here is a fixed script

if it is a local script:

local player = game.Players.LocalPlayer --grabs the player for the script

--//Services
local replicatedStorage = game:GetService('ReplicatedStorage')
local gui = player.PlayerGui --playergui is in the player
--//Variables
local rollEvent = replicatedStorage:WaitForChild('RollEvent')
local stamina = gui:WaitForChild('StaminaGui'):WaitForChild('Stamina')

--//OnServerEvent
rollEvent.OnServerEvent:Connect(function(h)
    stamina.Value = stamina.Value - 25 -- reduce stamina
end)

if it is server sided:


game.Players.Players.PlayerAdded:Connect(function(player)
--//Services
local replicatedStorage = game:GetService('ReplicatedStorage')
local gui = player.PlayerGui --playergui is in the player
--//Variables
local rollEvent = replicatedStorage:WaitForChild('RollEvent')
local stamina = gui:WaitForChild('StaminaGui'):WaitForChild('Stamina')

--//OnServerEvent
rollEvent.OnServerEvent:Connect(function(h)
    stamina.Value = stamina.Value - 25 -- reduce stamina
end)
end)

Accept and upvote if this helps!

6 comments

0

It works and i'll accept it but just wondering, is there a way to do it on the server side?

0

Just use a server side script.

0

I tried that by using GetPlayers and it didn't work on a server script, i'll test it out again just to be sure.

1

oh i will fix

0

nevermind, i figured it out but thanks!

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.