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

Checking Player Slots?

So i've been trying to script a slot system to check if a person has a weapon or in this case, flashlight and or deagle?

I've tried the

while true do

but this resulted in a crash. Odd?

--Variables--
flashlight = game.Players.LocalPlayer.Backpack:FindFirstChild("Flashlight")
deagle = game.Players.LocalPlayer.Backpack:FindFirstChild("Deagle")
slot1 = game.Players.LocalPlayer.PlayerGui.Backpack.Backpack.Slots.Slot1
slot2 = game.Players.LocalPlayer.PlayerGui.Backpack.Backpack.Slots.Slot2

--Functions--
if flashlight then
	print("Player has a Flashlight!")
	slot1.Text = "Flashlight"
elseif flashlight == nil then
	print("No Flashlight Found!")
	slot2.Text = "Empty Slot"
if deagle then
	print("Player has a Deagle!")
	slot2.Text = "Deagle"
elseif deagle == nil then
	print("No Deagle Found!")
	slot2.Text = "Empty Slot"
	end
end

So what im trying to do is make the script keep re-checking the player's slots and see if they sitll have the item without lagging the server?

So if anyone could help me? That be great.

Thanks in advanced?

NEW ISSUE

With the help of you guys, it seems to work to a point,

--Variables--
flashlight = game.Players.LocalPlayer.Backpack:FindFirstChild("Flashlight")
deagle = game.Players.LocalPlayer.Backpack:FindFirstChild("Deagle")
slot1 = game.Players.LocalPlayer.PlayerGui.Backpack.Backpack.Slots.Slot1
slot2 = game.Players.LocalPlayer.PlayerGui.Backpack.Backpack.Slots.Slot2

--Functions--
if flashlight and deagle then
	print("Player has a Flashlight!")
	slot1.Text = "Flashlight"
	print("Player has a Deagle!")
	slot2.Text = "Deagle"
while wait() do
	game.Players.LocalPlayer.Backpack:FindFirstChild("Flashlight")
	slot1.Text = "Empty Slot"
	game.Players.LocalPlayer.Backpack:FindFirstChild("Deagle")
	slot2.Text = "Empty Slot"
	end
end

Now the issue is, even though the player has the items, it will still return "Empty Slot"

2 answers

✓ Accepted answer

Try this.

--Variables--
slot1 = game.Players.LocalPlayer.PlayerGui.Backpack.Backpack.Slots.Slot1
slot2 = game.Players.LocalPlayer.PlayerGui.Backpack.Backpack.Slots.Slot2

--Functions--
game:GetService("RunService").RenderStepped(function() --this will run every 1/60th of a second
	local flashlight = game.Players.LocalPlayer.Backpack:FindFirstChild("Flashlight")
	local deagle = game.Players.LocalPlayer.Backpack:FindFirstChild("Deagle")
	if flashlight then -- they have a flashlight
		print("Player has a Flashlight!")
		slot1.Text = "Flashlight"
	else -- they don't have a flashlight
		print("No Flashlight Found!")
		slot2.Text = "Empty Slot"
	end
	if deagle then -- they have a deagle,
		print("Player has a Deagle!")
		slot2.Text = "Deagle"
	else -- they don't have a deagle
		print("No Deagle Found!")
		slot2.Text = "Empty Slot"
	end
end)

3 comments

0

I tried an "and" statement for this to check their character for when it's equiped but it checks both....Anything i can do?

1

replace with "or"

0

Thanks!

The reason while true do crashed you, is because that function runs extremely fast, and will crash any server you put it in, as true is always true, and it is trying to keep up.

Try replacing it with while wait() do

1 comment

0

I've editted my post with a new issue.

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