local Player = game.Players.LocalPlayer
for i,textbuttons in pairs(script.Parent.Frame:GetChildren()) do
if textbuttons:GetAttribute("GetWeapon") then
textbuttons.TextButton.MouseButton1Click:Connect(function()
local stop = false
for i,anims in pairs(Player.Character.Humanoid.Animator:GetPlayingAnimationTrack()) do
if anims.Name == "Swing1" or anims.Name == "Swing2" or anims.Name == "Swing3" then
stop = true
end
end
if Player.Character:GetAttribute("Attacking") then stop = true end
if stop then return end
Player.Character:SetAttribute("CurrentWeapon",textbuttons:GetAttribute("GetWeapon"))
end)
end
end
I tried the script to change weapons with the text button, but it doesn’t work. What should I fix?
All textbutton got ChangeWeapon Attribute.
Unless im wrong, I think that you need to indent the “if” statement along with the “end”. Are you getting any errors in the output when you click the buttons?
im still just trying to get a full understanding of the problem and make sure everything im seeing is correct
Im just going to write the whole thing out so you can tell me its what you want.
You have a script that cycles through all of the buttons and detects if one of them is being pressed.
The script gets the attribute GetWeapon which im assuming holds the weapon name? (correct me if im wrong)
You then check if a swinging animation is playing, so im assuming it would be if the player is currently using another weapon and stop the script? (again, correct me if im wrong)
Then you get the character attribute of attacking which is if there attacking using the weapon and if so you stop the script.
And if everything goes through, which should be the attribute attached to the textbutton, you set the players attribute to be the weapon that you want.
After reading what I said over more times than id like to admit, I get what you are trying to do. are you planning on adding more buttons?
Also sorry for poor organisation and help why dose my explanation of your script look like ai but anyways if my explination is missing something let me know so I can understand it better
I’m going to convey this message to you through translation. I’m sorry there may be incorrect words.
The system I am trying to make is the Combat system made by a youtuber named Liam. In this system, he changes his weapons using proxmity, but I want him to change his weapons by pressing from the gui.
If I need to explain the script:
Step 1 → Our script first detects the click and then tries to detect whether our character is attacking or not.
Step 2 → If the character is attacking, it does not allow changing weapons. If not attacking, it switches between weapons.
(This change is achieved with the Attribute called GetWeapon Sword, and an attirbute called GetWeapon has been added to each button.)
I tried to adapt what is in the video to suit myself, but I do not receive any warnings on the output and there is no weapon change.
From what I’ve seen in the tutorial Liam made, they use a Server Script to check whenever the attribute of the current weapon changes and then execute the line of command to actually switch between weapons.
The issue is that ProximityPrompts also uses Server Scripts to handle the Triggered event, which allows the script to change the attribute from the servers perspective. Since you’re using a GUI to change the weapon, they just work locally and the server can’t read local attribute changes.
The solution for this is to create a RemoteEvent and fire it through the client, just like below:
local Player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
for i,textbuttons in pairs(script.Parent.Frame:GetChildren()) do
if textbuttons:GetAttribute("GetWeapon") then
textbuttons.TextButton.MouseButton1Click:Connect(function()
local stop = false
for i,anims in pairs(Player.Character.Humanoid.Animator:GetPlayingAnimationTrack()) do
if anims.Name == "Swing1" or anims.Name == "Swing2" or anims.Name == "Swing3" then
stop = true
end
end
if Player.Character:GetAttribute("Attacking") then stop = true end
if stop then return end
RS.RemoteEvent:FireServer(textbuttons:GetAttribute("GetWeapon"))
end)
end
end
And then change it on a Server Script:
local RS = game:GetService("ReplicatedStorage")
RS.RemoteEvent.OnServerEvent:Connect(function(plr, weapon)
plr.Character:SetAttribute("CurrentWeapon",weapon)
end)
Hope this helps . If you need further assistance let me know below.
Thank u man now its work. When I tried it myself with the remote event, I was getting an error, but my problem was solved with the extra variable in yours.