How could i get this intvalue and change his intvalue.Value from another localscript?
intvalue = Instance.new("IntValue")
intvalue.Name = "Stamina"
How could i get this intvalue and change his intvalue.Value from another localscript?
intvalue = Instance.new("IntValue")
intvalue.Name = "Stamina"
Do you meant changing an IntValue from a local script?
Well you’d ned to parent the int value somewhere, and then the other local script can just access it by doing (place the object is parented).Stamina, then you can change its value accordingly.
That int value was instantiated from a localscript and I want to be able to change its value from a different localscript.
Ikd how to do that could you help me please
Then I assume you’ll need to fire a remote event and send an argument inside the FireServer() function. Then when the server receives it, just let the server handle the change.
intvalue.Parent = place you want it parented
Couldn’t you literally just make 2 Local Scripts, 1 for creating the IntValue & another for Changing the value when necessary? (Preferably through BindableEvents)
I need to do the next, when in the other localscript i press F key the intvalue change its .Value to -15, is it possible? and how to do that?
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
print("Playing defense animation! done.")
local playAnim = humanoid:LoadAnimation(defanim)
playAnim:Play()
-- I NEED TO DO IT HERE (CHANGE INT VALUE)
script.DefAnim:FireServer()
end
end)
If you’ve already defined the IntValue, you also need to parent it so adding onto your code in the first post in the local script that will create the IntValue:
local Player = game.Players.LocalPlayer
intvalue = Instance.new("IntValue")
intvalue.Name = "Stamina"
intvalue.Parent = Player
And in the other Local Script:
local Player = game.Players.LocalPlayer
local Stamina = Player:WaitForChild("Stamina") --The reason why we do WaitForChild() is that the variable will yield until it has been found
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
print("Playing defense animation! done.")
local playAnim = humanoid:LoadAnimation(defanim)
playAnim:Play()
Stamina.Value = Stamina.Value --Your Number here, make sure to add a + or - if you wanna change it
script.DefAnim:FireServer()
end
end)
I think there are a couple of other scripts that might have a Stamina value, so the Size/Offset is going crazy cause of the amount of changing & moving it’s doing
Is there any way to fix that?
it works?
intvalue.Changed:Connect(function()
frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)
end)
Try it and see? Also make sure to replace the IntValue with the Stamina variable
Something is wrong
local Stamina = player:WaitForChild("Stamina") --The reason why we do WaitForChild() is that the variable will yield until it has been found
local ydefault = 1
intvalue.Changed:Connect(function()
local frame = game.StarterGui.Game.Background.StaminaBar
frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)
end)
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
print("Playing defense animation! done.")
local playAnim = humanoid:LoadAnimation(defanim)
playAnim:Play()
Stamina.Value = Stamina.Value - 15 --Your Number here, make sure to add a + or - if you wanna change it
script.DefAnim:FireServer()
end
end)
ERROR
Players.MatiasHarders.PlayerGui.Game.AnimFrame.Animations:33: attempt to index nil with ‘Changed’
intvalue.Changed
You forgot to replace the intvalue
with the Stamina
variable aaaaaaaaa
frame size keeps changing:
local Stamina = player:WaitForChild("Stamina") --The reason why we do WaitForChild() is that the variable will yield until it has been found
local ydefault = 1
Stamina.Changed:Connect(function()
local frame = game.StarterGui.Game.Background.StaminaBar
frame.Size = UDim2.new(Stamina.Value/100,0,ydefault, 0)
end)
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
print("Playing defense animation! done.")
local playAnim = humanoid:LoadAnimation(defanim)
playAnim:Play()
Stamina.Value = - 15 --Your Number here, make sure to add a + or - if you wanna change it
script.DefAnim:FireServer()
end
end)
video:
rbbb.wmv (638,2 KB)
Just delete all the lines of code that may have that Stamina value & changing the Udim Size/Offset, that’s probably the only think I can think of
Thanks you:D it works thanks you a lot