#Why is this attribute returning Nil but not others?

128 messages · Page 1 of 1 (latest)

viral lotus
#

I can provide any other info from the scripts n stuff you need

pseudo zinc
#

How would anyone figure that out if you never share the code?

crimson vector
#

Where

viral lotus
#

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

crimson vector
#

So what problem

pseudo zinc
#

A simple solution for you is to bind a signal to that attribute whenever it chages

viral lotus
#

My plan was to originally increment it, but i cant do that as it can find the attribute i believe

crimson vector
#

Theirs ** no built-in method called getAttribute or setAttribute **

#

But until 2022

#

they added it

viral lotus
#

wdym?

crimson vector
#

I don’t know

viral lotus
#

my other uses of it works properly

crimson vector
#

Yeah

viral lotus
#

and its in documentation

pseudo zinc
#

@crimson vector shut up for a moment 😭

#

You're not even setting attribute anywhere in the code you shared @viral lotus

#

It's ``` not '''

crimson vector
#

Helps*

viral lotus
sharp sageBOT
#

studio** You are now Level 2! **studio

pseudo zinc
#

@viral lotus where do you set the attribute?

crimson vector
#

To 5

viral lotus
#

like from here

crimson vector
#

Or 3

pseudo zinc
#

And what is nil?

#

Stunned or stuncounter

viral lotus
#

StunCounter

#

Stunned works properly

pseudo zinc
#

Great work Sherlock

crimson vector
#

how did you create that value ( Just want to know )

#

,,,playerDataStore:SetAsync(player.UserId .. "_Stunned", true)
playerDataStore:SetAsync(player.UserId .. "_StunCounter", 0),,,

sharp sageBOT
#

studio** You are now Level 3! **studio

royal fieldBOT
#

ActiveVenue

crimson vector
#

So pro embed failed

#

Oh yay im yellow

crimson vector
# viral lotus ?

Add dis playerDataStore:SetAsync(player.UserId .. "_Stunned", true)
playerDataStore:SetAsync(player.UserId .. "_StunCounter", 0)

pseudo zinc
#

Why datastore??

#

How is datastore related??

crimson vector
#

it took me 50 seconds to make it dont ask any questions

pseudo zinc
#

@viral lotus under what is that attribute created in the explorer??

crimson vector
#

If you insists datastore allows an player to save things

pseudo zinc
#

How is that related to the nil attribute?

crimson vector
#

Trust me it works for setting prefix

viral lotus
pseudo zinc
#

Yeah of course it's not going to work

crimson vector
#

player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0

pseudo zinc
#

@viral lotus ignore ActiveVenue he's got a brain rot

crimson vector
#

I agree

#

Now I will help other people

pseudo zinc
#

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

viral lotus
#

would that be in this script (serverSide) or a StartingPlayerScript

pseudo zinc
#

In a script server side

viral lotus
#

alright

#

let me test it

rough marsh
#

correction:

Player:SetAttribute("abc", true)
pseudo zinc
#

Yeah thank you just wanted to edit the message

viral lotus
pseudo zinc
#

I don't have a computer to verify with so I use my memory.

crimson vector
#

local Players = game:GetService("Players")

local function onPlayerAdded(player)
player:SetAttribute("abc", true)
end

Players.PlayerAdded:Connect(onPlayerAdded)

viral lotus
#

wait minor spelling misatke

pseudo zinc
#

On is uppercased

viral lotus
#

still got the error after fix

crimson vector
#


humanoid:SetAttribute("StunCounter", 0)


local StunCounter = 0 humanoid:GetAttribute("MyCustomAttribute")
print(StunCounter) ```
rough marsh
#

it is case sensitive

pseudo zinc
#

And add to the top

local Players = game:GetService("Players")
crimson vector
#

local Players = game:GetService("Players")

#

But dis better game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)

pseudo zinc
rough marsh
#

long and hard to read

pseudo zinc
crimson vector
#

Wait so you want to make a client side?

sharp sageBOT
#

studio** You are now Level 4! **studio

crimson vector
rough marsh
pseudo zinc
crimson vector
#

Color is an opinion!

pseudo zinc
viral lotus
#

i think its working?

crimson vector
#

Add the print

viral lotus
#

okay yeah it is

pseudo zinc
#

It should be, check in the workspace if it's added to the player

viral lotus
#

do you know why Stunned work but not StunCounter?

#

prior to this*

crimson vector
#

I suggest over complicating it

pseudo zinc
#

Oh wait

#

Okay hold on while I recode the whole thing

crimson vector
#

Do you mean recode?

pseudo zinc
#

I completely unnoticed you're using an event

crimson vector
#

Replicatedstorage eventfunction or event

pseudo zinc
crimson vector
rough marsh
#

rewrite*

viral lotus
#

does ++ not exist in lua or something

pseudo zinc
crimson vector
pseudo zinc
viral lotus
#
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)
crimson vector
pseudo zinc
#

Use this next time

crimson vector
#

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👍

crimson vector
#

Who?

viral lotus
#

im coming from godot and a bit of special java so these specifics are very new to me

crimson vector
#

Why is no one helping me in keyboard gui thingy

crimson vector
#

Theirs clearly an Humanoid misspelling

pseudo zinc
#
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.

viral lotus
#

Minor Capitalization mistake

#

but yeah that works and is much cleaner than mines

#

tysm

crimson vector
#

Yes

#

Thank me

pseudo zinc
#

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)