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

HttpService is not allowed to access ROBLOX resources?

I am making a Script builder and i made a Create Http , But there are some errors

if string.sub(m,1,3):lower() == ("ch/") then
				local subj = string.sub(m,4)
				local hs = game:GetService("HttpService")
				
				local link = string.sub(m,string.find(subj,"/")+1)
				subj = string.sub(m,4,string.find(subj,"/")-1)
				
				
				local int = Instance.new("StringValue",desk.outPut.Scripts)
			local gotAllowed = true
			local reason
			for _,x in pairs(desk.outPut.Scripts:GetChildren()) do
				if x.Name == subj then
					gotAllowed = false
					reason = "Script already exists"
				end
			end
			if subj:find(" ") then
				gotAllowed = false
				reason = "Script Name is not available for use"
			end
			if gotAllowed == false then
				sendOutMessage(reason,"error")
				int:Destroy()
				return ;
			else
				
			int.Name = subj
			int.Value = hs:GetAsync(link)
			addScript(subj)
			end
			end

First, i do ch/hello/https://pastebin.com/raw/U0GBSQDL for example, and what i get is a value with the name "he" and without a Value, Can i get some help please

3 comments

0

You cannot access roblox.com from the HTTP service

0

I'm not trying to acess roblox.com

0

Im trying to access pastebin.com

1 answer

✓ Accepted answer

Okay, so to figure out why this isnt working, I'd start by trying to narrow down to what is actually causing the problem. In your case, my guess is either the HttpService itself, or the way you are manipulating either the user input.

So - lets test if it is the http service! I quickly added a new script, and typed in the following:

local hs = game:GetService("HttpService")
print(hs:GetAsync("https://pastebin.com/raw/U0GBSQDL"))

After running that, success, the code located at the pastebin link was printed into the console. So by doing this, we have proved that the httpservice itself is not the issue, so the issue must be in how you are either reading the user input.

Lets do some further tests to figure out where the issue is. I commented out my original code, and entered the following:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(m)
		if string.sub(m,1,3):lower() == "ch/" then
			print("Getting name + link")
			local subj = string.sub(m,4)
			local name = string.sub(m,4,string.find(subj,"/")-1)
			local link = string.sub(m,string.find(subj, "/")+1)
			print(name)
			print(link)
		end
	end)
end)

When I ran this, and typed into chat (ch/hello/https://pastebin.com/raw/U0GBSQDL) as you said before, I got the same results as you, the console read

Getting name + link

he

lo/https://pastebin.com/raw/U0GBSQDL

So, we found the issue, how can we go about fixing it. Well, lets rewrite how you are splitting up your message string. Here is my code now:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(m)
		if string.sub(m,1,3):lower() == "ch/" then
			--We know the first 3 characters are 'ch/' so lets ignore them
			m = string.sub(m, 4)
			--We now know the string is in the format NAME/LINK
			--So lets search for the / character
			local charPos = string.find(m, "/")
			--We now know where the / character is, lets split!
			local name = string.sub(m, 1, charPos-1)
			local link = string.sub(m, charPos + 1)
			--Print to console
			print(name)
			print(link)
		end
	end)
end)

And after chatting the original message again, success! We have extracted the name and the link from the message - the console now reads

hello

https://pastebin.com/raw/U0GBSQDL

So, we've located the problem and solved it! I'll leave integrating the new splitting function into your code to you, if you have trouble let me know.

Hope this helps, happy coding :)

1 comment

0

Thanks a lot, this was painful for me

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