#Need script to make a button break tool
170 messages · Page 1 of 1 (latest)
Then line 17 is attempting to get a backpack object from that table which will output an error
Can I see the LocalScript that fires the RemoteEvent?
sry for not replying sooner
Its in the button btw
Got it
I'll have to hop on my PC to try and rewrite the script
So it'll be a minute
Sorry about that
its fine i can wait all day im desperate
Okay so let me clarify
You have a tool which when equiped will display a UI where you can type a player's name and kill them (you said this part works) and a button that destroys the tool equipped?
the button is used to kill the player
i want it to destroy the tool as well
the user has to type the target's name in the text box and press the button to kill. since i dont want the player to own the tool forever i want the button to destroy the tool as well
Got it
** You are now Level 2! **
So it's a one time use thing
exactly
** You are now Level 2! **
So I've gone and recreated what you have
I've made a tool and a UI that only shows when you have the tool equipped
Here is the GUI
So here is what I changed to the button script
local btn = script.Parent
local textBox = script.Parent.Parent.TextBox -- rename this to your text box
local players = game:GetService("Players")
local target
btn.MouseButton1Click:Connect(function()
local text = textBox.Text
if players:FindFirstChild(text) then
local target = players:FindFirstChild(text)
game.ReplicatedStorage.KillPlayer:FireServer(target)
end
end)
This sends 2 variables to the remote event. The owner of the tool (To destroy the tool) and the target (To kill the target)
Then over in the Remote Event Script, we have this
game.ReplicatedStorage.KillPlayer.OnServerEvent:Connect(function(player, target)
local backpack = player:FindFirstChild("Backpack")
local character = player.Character
local tool = backpack:FindFirstChild("Tool") or character:FindFirstChild("Tool") -- This would be the tool's name
local targetCharacter = target.Character
local humanoid = targetCharacter.Humanoid
tool:Destroy()
humanoid.Health = 0
end)
This gets the tool from the owner variable (player) and destroys it
And it sets the humanoid of the target variable to zero
So if you want, you can use this and let me know if it works.
Alr I'm going to try it out
Should I name "Tool" with the name of the tool?
I changed the textbox name and tool but it doesn't work
I'm going to see if I can do smtg about it
It doesnt work
It doesnt kill the player as well
I dont think the local script is fine
Oh wait
Targeter is a remote event
Ok so
The first line was the reason why it didn't work
The problem is
Yes now it breaks the tool but the button gui and the text box are still there
I think if we make it destroy the button and the text box as well it will work
I decided to keep the local script
And keep you server script
Now I need to make it destroy the button and the text box
I think if we local the text box and the button and destroy them, it will work as I wa t
Okay so everything is working apart from the text box staying there?
Yea and the button
** You are now Level 3! **
Ok
So yeah, you can make the server script destroy the GUI as well
And it should work
Do u know how to define them?
It's just player.PlayerGUI.(GUI name):Destroy()
And GUI name is just the name of the GUI where the text box and button is
This will work if you put it in the remote event script
With tool:Destroy()?
The next line after tool:Destroy?
I'm going to try it
Not working
Maybe it's better if I show it to you
i just added 2 lines after tool:Destroy()
By define I meant local
let me show it to u
And that works, right?
That's really weird
Yeah if the frame is in the tool, it should be destroyed
Can I see the local script?
I think I have a solution
Which one
A sec
One of them has to be deleted
You mean the one after KillTarget?
its the one that allows the button and the text to show up when the tool is equiped
i think this way might work
i added line 6
Change line 6 to this
** You are now Level 3! **
local ScreenGui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("OpenButton")
What could be the issue is that the script in the tool is a local script but this should probably work
If it gives an error saying "Attempt to index nil with "ScreenGui" then I know how to fix it
Yea now it doesn't destroy the tool
I never test on studio, I just join the game with my alt, if u want me to show u the error then I need some time
Idk how to use my alt and my main at the same time
** You are now Level 4! **
Do u need to see the error?
Instead of "ScreenGui" it says "PlayerGui"
Are they the same thing
No
So it can't find the player's PlayerGui
I guess what you could try to do is
local ScreenGui = player.PlayerGui:FindFirstChild("OpenButton")
Oh yeah I see the problem
game.Players.LocalPlayer can only be called in a local script
It should be working now
Does it show any errors?
Ok
They still stay
Is it possible to make a normal script that breaks the tool and the gui in the button?
It's going to be fine if the user loses the tool without typing
I see what the problem is
The local script in the tool only clones the GUI on the client's side, meaning it's not actually there in the server
When you clone the tool, does it go to the player's character or backpack?
The one under the tool?
Or button
Because I don't see character or backpack anywhere
Where is the script that moves the tool from ServerStorage to the player
Unless it moves to the player on it's own
Ok
Okay got it
backpack
So what you need to do is go to the tool and replace the local script in the tool with a regular script
This one
I'll give you a modified version of the original one
Because it wouldn't work in a regular script
Ok
local ui = script:WaitForChild("OpenButton")
local player = script.Parent.Parent.Parent
script.Parent.Equipped:Connect(function()
local screenGui = ui:Clone()
screenGui.Parent = player.PlayerGui
end)
script.Parent.Unequipped:Connect(function()
player.PlayerGui:FindFirstChild(ui.Name):Destroy()
end)
Try this
I'm going to test it now
I'm going to see if it has errors
"Character"
I'm going to test it on my alt in the game but it might take 1min
Wow perfect
It works now
Tysm I spent half day to make this work
No problem