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

Why doesn't my script give rooms when I say "Room"?

(I have the "Room100A" at the ServerStorage) The problem is that it should give me a room when I say "Room", but it doesn't. Please tell me what's wrong with it.

while true do
wait()
	function onChatted(msg)
		if msg == "Room" then
			local enabled = true	
			if game.Players.LocalPlayer.Backpack:findFirstChild(tostring("Room100A")) == nil and enabled == true then
			game.ServerStorage:findFirstChild(tostring("Room100A")):clone().Parent = game.Players.LocalPlayer.Backpack
			enabled = false
			end
		end
	end
end

2 comments

1

You are only repeatedly defining a function. There is no event listener or anything actually calling the function. You're also calling tostring on a literal string.

0

So I should change torstrings for strings? That would be it?

1 answer

✓ Accepted answer

You do not have any way of calling on the function. It needs to have a separate event calling on it before you can actually do anything inside

Here is what I recommend:

local player = game.Players.LocalPlayer
local room = game.ServerStorage:FindFirstChild(tostring("Room100A"))

function onChatted(msg)
	if msg == "Room" then
		local enabled = true    
		if player.Backpack:FindFirstChild(tostring("Room100A")) == nil and enabled then
			room:clone().Parent = game.Players.LocalPlayer.Backpack
			enabled = false
		end
	end
end

player.Chatted:connect(function(msg) onChatted(msg) end) 

**Note: ** Make sure this is in a LocalScript or else you can't call LocalPlayer.

1 comment

0

Thank you!

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