Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Is This Script Not Working Right?

local player = script.Parent.Parent.Parent.Parent.Parent
local gun = player.Backpack:FindFirstChild("Revolver") or player.Character:FindFirstChild("Revolver")
local tex = script.Parent.Text
script.Parent.MouseButton1Click:connect(function()
	if gun ~= nil then
		script.Parent.Text = "Gun Found"
		wait(1)
		script.Parent.Text = tex
	elseif gun == nil then
		script.Parent.Text = "Gun Not Found"
		wait(1)
		script.Parent.Text = tex
	end
end)

this script is in a buttongui. i want the button gui change text to 'Gun Found' if gun is not nil but if the gun is nil i want the buttongui to change text to 'Gun Not Found'. it changes text if the gun is not found but when i place a gun in player backpack or in player the gui button will still change the text to 'Gun Not Found' it will not change the text to 'Gun Found' if the gun is found

3 comments

0

I've corrected a few issues with the script I've given you. Try it out, I'm in school right now so if there's a problem let me know please.

0

Couldn't you use a local script? That would work better for screen GUIs. If Acheo's fixes don't help I would just put this code in a local script. That would mean that for line one use local Player = game.Players.LocalPlayer. Try it if you're still having trouble.

0

i tried using local script but that would only work for studio it would not work on the roblox player

1 answer

✓ Accepted answer
wait(1)
local player = script.Parent.Parent.Parent.Parent.Parent
local button = script.Parent
local currentText = button.Text

button.MouseButton1Click:connect(function()
if player.Backpack:FindFirstChild("Revolver") ~= nil or player.Character:FindFirstChild("Revolver") ~= nil then

	button.Text = "Gun Found"
	wait(1)
        script.Parent.Text = currentText

elseif if player.Backpack:FindFirstChild("Revolver") == nil and player.Character:FindFirstChild("Revolver") == nil then
	button.Text = "Gun Not Found"
	wait(1)
        script.Parent.Text = currentText
    end
end)

2 comments

0

thank you for the help it works now

0

Welcome.

This discussion is preserved as it was. New answers, comments, and votes are closed.