#Why is this attribute returning Nil but not others?
128 messages · Page 1 of 1 (latest)
How would anyone figure that out if you never share the code?
i mean all cases of using that attribute returns nil, but heres the code for this script
`
local bindableEvent = game.ServerScriptService:WaitForChild("Stun")
local function onMyEventFired(player,length)
-- Your code to run when the event is triggered
local BaseSpeed = player.Character.Humanoid.WalkSpeed
local BaseJump = player.Character.Humanoid.JumpPower
local StunCounter = player:getAttribute("StunCounter")
print(player.Name)
player:setAttribute("Stunned", true)
print(player:getAttribute("StunCounter"))
print(player:getAttribute("Stunned"))
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0
end
bindableEvent.Event:Connect(onMyEventFired)
`
not finished
So what problem
My plan was to originally increment it, but i cant do that as it can find the attribute i believe
Theirs ** no built-in method called getAttribute or setAttribute **
But until 2022
they added it
wdym?
I don’t know
my other uses of it works properly
Yeah
and its in documentation
@crimson vector shut up for a moment 😭
You're not even setting attribute anywhere in the code you shared @viral lotus
It's ``` not '''
Helps*
is it not default set from the properties area?
** You are now Level 2! **
@viral lotus where do you set the attribute?
To 5
like from here
Or 3
Great work Sherlock
how did you create that value ( Just want to know )
,,,playerDataStore:SetAsync(player.UserId .. "_Stunned", true)
playerDataStore:SetAsync(player.UserId .. "_StunCounter", 0),,,
** You are now Level 3! **
ActiveVenue
Add dis playerDataStore:SetAsync(player.UserId .. "_Stunned", true)
playerDataStore:SetAsync(player.UserId .. "_StunCounter", 0)
it took me 50 seconds to make it dont ask any questions
@viral lotus under what is that attribute created in the explorer??
If you insists datastore allows an player to save things
How is that related to the nil attribute?
Trust me it works for setting prefix
StarterCharacter, "Attributes" under the properties explorer if you meant that
Yeah of course it's not going to work
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0
@viral lotus ignore ActiveVenue he's got a brain rot
You need to create these attributes when the player joins
Example:
function onPlayerAdded(Player)
Player:SetAttribute("abc") = true
end
Players.PlayerAdded:connect(OnPlayerAdded)
Sorry for any spelling issues it's my phone keyboard
would that be in this script (serverSide) or a StartingPlayerScript
In a script server side
correction:
Player:SetAttribute("abc", true)
Yeah thank you just wanted to edit the message
I don't have a computer to verify with so I use my memory.
local Players = game:GetService("Players")
local function onPlayerAdded(player)
player:SetAttribute("abc", true)
end
Players.PlayerAdded:Connect(onPlayerAdded)
wait minor spelling misatke
On is uppercased
still got the error after fix
Add print function
humanoid:SetAttribute("StunCounter", 0)
local StunCounter = 0 humanoid:GetAttribute("MyCustomAttribute")
print(StunCounter) ```
it is case sensitive
And add to the top
local Players = game:GetService("Players")
local Players = game:GetService("Players")
But dis better game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)
It's a server script issue and unrelated to the humanoid.
long and hard to read
They're the exact same thing
Wait so you want to make a client side?
** You are now Level 4! **
It looks better
no it aint
No he doesn't need it to be a client side
Color is an opinion!
It's a matter of preference
i think its working?
okay yeah it is
It should be, check in the workspace if it's added to the player
I suggest over complicating it
Do you mean recode?
I completely unnoticed you're using an event
Replicatedstorage eventfunction or event
re-code
Did you mean “re-code”
rewrite*
does ++ not exist in lua or something
Can you please send the whole code in chat?
In Lua it's +=
local bindableEvent = game.ServerScriptService:WaitForChild("Stun")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
player:SetAttribute("StunCounter", 0)
end
Players.PlayerAdded:Connect(onPlayerAdded)
local function onMyEventFired(player,length)
-- Your code to run when the event is triggered
local BaseSpeed = player.Character.Humanoid.WalkSpeed
local BaseJump = player.Character.Humanoid.JumpPower
local StunCounter = player:getAttribute("StunCounter")
--print(player.Name)
player:setAttribute("Stunned", true)
print(player:getAttribute("StunCounter"))
--print(player:getAttribute("Stunned"))
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0
end
bindableEvent.Event:Connect(onMyEventFired)
No its +++++++++
player:getAttribute and player:setAttribute should be player:GetAttribute and player:SetAttribute, as Lua is case-sensitive.
Or attibute lua
Laughing out loud
You have now chatted 100+ message in 20 minutes👍
im coming from godot and a bit of special java so these specifics are very new to me
Why is no one helping me in keyboard gui thingy
You need to ensure that player.Character and player.Character.Humanoid
Theirs clearly an Humanoid misspelling
local bindableEvent = game.ServerScriptService:WaitForChild("Stun")
local function onMyEventFired(Player, Length)
local Character = Player.Character
if not Character then return end
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return end
local BaseSpeed = Humanoid.WalkSpeed
local BaseJump = Humanoid.JumpPower
local StunCounter = Player:getAttribute("StunCounter")
Player:setAttribute("Stunned", true)
Player:SetAttribute("StunCounter", 0)
print(Player:getAttribute("StunCounter"))
print(player:getAttribute("Stunned"))
Player.Character.Humanoid.WalkSpeed = 0
Player.Character.Humanoid.JumpPower = 0
end
bindableEvent.Event:Connect(onMyEventFired)
This should work as intended
Just saying it's incredibly painful to do this through an app.
Minor Capitalization mistake
but yeah that works and is much cleaner than mines
tysm
No problem
I forgot to optimize some stuff because I rushed.
Here are the full changes:
local ServerScriptService = game:GetService("ServerScriptService")
local BindableEvent = ServerScriptService:WaitForChild("Stun")
local function Stun(Player, Length)
local Character = Player.Character
if not Character then return end
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return end
local BaseSpeed = Humanoid.WalkSpeed
local BaseJump = Humanoid.JumpPower
Player:setAttribute("Stunned", true)
Player:SetAttribute("StunCounter", 0)
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
end
BindableEvent.Event:Connect(Stun)