#Need script to make a button break tool

170 messages · Page 1 of 1 (latest)

tepid kraken
#

You player variable is returning a table (line 12)
game.Players:GetPlayers()
returns a table of every player.

#

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?

pseudo pagoda
#

Ok

pseudo pagoda
#

Its in the button btw

tepid kraken
#

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

pseudo pagoda
#

its fine i can wait all day im desperate

tepid kraken
#

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?

pseudo pagoda
#

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

tepid kraken
#

Got it

toxic doveBOT
#

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

tepid kraken
#

So it's a one time use thing

pseudo pagoda
#

exactly

toxic doveBOT
#

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

tepid kraken
#

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.

pseudo pagoda
#

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

tepid kraken
#

Okay so everything is working apart from the text box staying there?

pseudo pagoda
#

Yea and the button

toxic doveBOT
#

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

tepid kraken
#

Ok

#

So yeah, you can make the server script destroy the GUI as well

#

And it should work

pseudo pagoda
#

Do u know how to define them?

tepid kraken
#

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

pseudo pagoda
#

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

tepid kraken
#

Okay so the 'TextButton' after GUI

#

Is that the name of the ScreenGUI?

pseudo pagoda
#

let me show it to u

tepid kraken
#

Ok

#

Wait

#

I know the problem

pseudo pagoda
tepid kraken
#

Oh

#

How does the script in KillTarget work?

pseudo pagoda
#

its a tool that

#

once u equip it, the framde becomes visible

tepid kraken
#

And that works, right?

pseudo pagoda
#

yea

#

the text box and the buttom are still there when the tool is destroyed

tepid kraken
#

That's really weird

pseudo pagoda
#

so im thinking if we could destroy the frame now

#

with the tool

tepid kraken
#

Yeah if the frame is in the tool, it should be destroyed

#

Can I see the local script?

#

I think I have a solution

pseudo pagoda
#

Which one

#

A sec

#

One of them has to be deleted

#

You mean the one after KillTarget?

tepid kraken
#

Oh mb
The local script under the tool

#

Yea

pseudo pagoda
#

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

tepid kraken
#

Change line 6 to this

toxic doveBOT
#

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

tepid kraken
#
local ScreenGui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("OpenButton")
pseudo pagoda
#

Yea that looks better

#

I'm going to test it

tepid kraken
#

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

pseudo pagoda
#

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

tepid kraken
#

Okay

#

That's fine

pseudo pagoda
#

Idk how to use my alt and my main at the same time

toxic doveBOT
#

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

pseudo pagoda
#

Do u need to see the error?

pseudo pagoda
#

Are they the same thing

tepid kraken
#

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

pseudo pagoda
#

Nope

#

This time it kills the player but the text and button stay

tepid kraken
#

Does it show any errors?

pseudo pagoda
#

A sec

#

"Character"

#

Maybe I should give one more try

#

I'm going to test it again

tepid kraken
#

Ok

pseudo pagoda
#

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

tepid kraken
#

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?

pseudo pagoda
#

The one under the tool?

#

Or button

#

Because I don't see character or backpack anywhere

tepid kraken
#

Where is the script that moves the tool from ServerStorage to the player

#

Unless it moves to the player on it's own

pseudo pagoda
#

In starter gui

#

Let me show u the script

tepid kraken
#

Ok

pseudo pagoda
#

If I can find it

#

It's a normal script in serverscriptservice

#

A sec

tepid kraken
#

Okay got it

pseudo pagoda
#

backpack

tepid kraken
#

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

pseudo pagoda
#

Should I copy and paste the script

#

The lines inside the local script

tepid kraken
#

I'll give you a modified version of the original one

#

Because it wouldn't work in a regular script

pseudo pagoda
#

Ok

tepid kraken
#
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

pseudo pagoda
#

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

tepid kraken
#

No problem