You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
i want to have an ability attribute that gets created on a player which will then allow the script to check what ability you have, meaning i can change abilities. -
What is the issue? Include screenshots / videos if possible!
whenever I attempt to reference the attribute in the server script that manages my ability, it returns as nil. i’m confused on why this is happening cause the attribute is not nill in the properties tabs in the game. i had the same problem with the damage but found a fix because it is a set number but it doesn’t work for the ability script. you can see this via the image included
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
ive attempted to find help in other places but i couldn’t find anything
there are 2 major scripts that use the ability attribute, this is the code for the local one (this is where i create it, the other parts of it isnt too important"
uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
wait(0.5) --allows time for player to load in
player:SetAttribute("ability", "stoneSkin")
local canPunch = true
local count = 1
local debounce = 0.8
damage = player:GetAttribute("damage")
local abilityActived = false
local char = player.Character
local mouse = player:GetMouse() -- gets player's mouse
local ability = script:GetAttribute("ability")
print(damage)
local punchAnimations = {
script:WaitForChild('punch1'),
script:WaitForChild('punch2'),
} -- stores all animations in a table
wait(1)
local player = game.Players.LocalPlayer
uis.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.Q then
if abilityActived == false then
game.ReplicatedStorage.Remote.activatePower:FireServer()
abilityActived = true
else if abilityActived == true then
game.ReplicatedStorage.Remote.deactivatePower:FireServer()
abilityActived = false
end
end
end
end)
while true do
wait()
local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") --gets hum
mouse.Button1Down:Connect(function() -- checks if mouse is clicked
if canPunch == true then
canPunch = false
count = (count%#punchAnimations)+1
local Animations = hum:LoadAnimation(punchAnimations[count]) -- plays the animation the count is up to
Animations:Play() -- plays the animation
Animations.Looped = false
game.ReplicatedStorage.Remote.punch:FireServer(damage) -- damages player
wait(debounce) -- wait for cooldown
canPunch = true
end
end)
end
and then there is the server script where im attempting to apply the changes
game.ReplicatedStorage.Remote.activatePower.OnServerEvent:Connect(function(player)
local char = player.Character
local damage = player:GetAttribute("damage")
local ability = player:GetAttribute("ability")
if damage == nil then
damage = 10 -- Set a default value for the attribute
end
print(damage)
print(ability)
if player:GetAttribute("ability") == "stoneSkin" then
damage = damage * 2
print(damage)
-- Rest of your code...
char = player.Character
char.Head.Attachment.rightFire.Enabled = true
char.Head.Attachment2.leftFire.Enabled = true
char.Head.BrickColor = BrickColor.new("Dark stone grey")
char.Torso.BrickColor = BrickColor.new("Dark stone grey")
char["Right Arm"].BrickColor = BrickColor.new("Dark stone grey")
char["Left Arm"].BrickColor = BrickColor.new("Dark stone grey")
char["Right Leg"].BrickColor = BrickColor.new("Dark stone grey")
char["Left Leg"].BrickColor = BrickColor.new("Dark stone grey")
char.Humanoid.MaxHealth = char.Humanoid.MaxHealth * 2
char.Humanoid.Health = char.Humanoid.Health * 2
player:SetAttribute("damage", damage)
elseif player:GetAttribute("ability") == "needles" then
print("needles")
end
end)
game.ReplicatedStorage.Remote.deactivatePower.OnServerEvent:Connect(function(player)
local char = player.Character
local damage = player:GetAttribute("damage")
if damage == nil then
damage = 10 -- Set a default value for the attribute
end
if player:GetAttribute("ability") == "stoneSkin" then
-- Rest of your code...
char.Head.Attachment.rightFire.Enabled = false
char.Head.Attachment2.leftFire.Enabled = false
char.Head.BrickColor = BrickColor.new("Medium stone grey")
char.Torso.BrickColor = BrickColor.new("Dark stone grey")
char["Right Arm"].BrickColor = BrickColor.new("Medium stone grey")
char["Left Arm"].BrickColor = BrickColor.new("Medium stone grey")
char["Right Leg"].BrickColor = BrickColor.new("Medium stone grey")
char["Left Leg"].BrickColor = BrickColor.new("Medium stone grey")
char.Humanoid.MaxHealth = char.Humanoid.MaxHealth / 2
char.Humanoid.Health = char.Humanoid.Health / 2
player:SetAttribute("damage", damage / 2)
elseif player:GetAttribute("ability") == "needles" then
print("needles off")
end
end)