Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

0
The downside to using ReplicatedStorage is that exploiters can gain access to it. Dovydas1118 1495 — 4y
Ad

Answer this question