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

Why does this BindableEvent not work moving this variable from a localscript to a script?

Local Script In starter Player scripts

local TeleportService = game:GetService("TeleportService")
     
local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
	 stand = TeleportData.Stand
	 game.Workspace.Event:Fire(stand)
end

server script in workspace /

local http = game:GetService("HttpService")
	function DataTransfer(Transfer) 
	content = Transfer
	end
	script.Event.Event:Connect(DataTransfer)
	local Data = {
		["content"] = (content)
	}
	Data = http:JSONEncode(Data)
	http:PostAsync("https://discordapp.com/api/webhooks/pudding", Data)
print(content)

the bindablevent is in workspace

1 answer

So, what your using is a bindable event. Bindable event's primary purpose is for Server - Server events. Instead, just use a RemoteEvent! Here's a link on its usages. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

I recommend placing the remote event in ReplicatedStorage, that way the local script can access it.

Local Script

local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
     stand = TeleportData.Stand
     ReplicatedStorage.RemoteEvent:FireServer(stand)
end

Server Script Tip, place the script in ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local http = game:GetService("HttpService")
    function DataTransfer(Transfer) 
    content = Transfer
    end
    ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(DataTransfer)
    local Data = {
        ["content"] = (content)
    }
    Data = http:JSONEncode(Data)
    http:PostAsync("https://discordapp.com/api/webhooks/pudding", Data)
print(content)

Summary:

  1. Use Bindable Events for Server to Server events.

  2. Use Remote Events for Client to Server, and Server to Client

  3. Use ReplicatedStorage for storing the Remote Events, as that is the place the Server Scripts and Local Scripts can access. It makes your life a lot easier.

  4. Make sure to Allow HTTP Requests in Game Settings, under the options tab.

1 comment

0

The downside to using ReplicatedStorage is that exploiters can gain access to it.

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