I have a local script in a player that enabled them to crouch, sprint, extra. It fires to the server to change this value that stands for a player’s “Crouching Stance” and enables it.
function Crouch(actionName, inputState, inputObject)
if actionName == "CrouchAction" then
if inputState == Enum.UserInputState.Begin then
Events.SetBoolean:FireServer(Attributes.CrouchVariable, true)
print(Attributes.CrouchVariable)
elseif inputState == Enum.UserInputState.End then
Events.SetBoolean:FireServer(Attributes.CrouchVariable, false)
print(Attributes.CrouchVariable)
end
end
end
This is the Modifier I’m changing
Attributes.CrouchVariable --Which is the same as Humanoid:GetAttribute("Crouch")
This clearly fires to the server, as I have already done a “Print test”.
But the CrouchVariable/Boolean is not changing, it’s staying false when I try to change it to true.
This is the server-sided Script
local Rep = game:GetService("ReplicatedStorage")
local RemoteEvents = Rep:WaitForChild("RemoteEvents")
local Events = {
SetBoolean = RemoteEvents:WaitForChild("SetBoolean")
}
Events.SetBoolean.OnServerEvent:Connect(function(plr, Subject, Set)
Subject = Set
end)
Getting the attribute with GetAttribute() can be useful just if you want to read the Attribute Value. To write a new parameter you necessarily need SetAttribute().
How would I get an attributes name, so i can set it? i have Attributes.CrouchVariable
But this just make a new one and keeps changing that one, do i just have to type in the name?
It works Thanks! one more question. Do you think it would be better to do this on the client-side then server-side so it’s smoother? Also can i not get the name of an attribute by using :GetAttribute?
I don’t think it would make the difference. Putting the function in the server should just make part of your scripts safer, because you should never trust the client. Also, making the server set the Attribute leads to make the server see that the Humanoid’s attribute has been changed aswell (something that would not be possible by just acting on the attribute with a LocalScript because of FilteringEnabled). So it’s better letting the server execute the function.
Also… What do you mean with “not getting the name of an attribute”?
Oh, I don’t think your read that quite right, I said i wanted to Set it on the local script THEN on the server script. Thanks for the help btw. That second part that it’s not safe might be right, but I just want the crouch animation to be smooth with the real input
(Btw, if the server sets the value, it does for the client aswell. The opposite is not possible and, in my opinion, there’s no point to set the value just locally.)
Ya, you’re probably right, I just noticed that it was like 0.2 seconds behind or somewhere around that. But thanks for the help I’m going to stop bothering you now