I was going through some code (again) and found this:
game:GetService("AdService"):ShowVideoAd()
game:GetService("AdService").VideoAdClosed:connect(function()
print("Finished showing video ad.")
end)
-- Script
-- Create RemoteEvent to handle turning on ForceField and put it
-- in ReplicatedStorage so both Server and Client can see it
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "ForceFieldEvent"
remoteEvent.Parent = game.ReplicatedStorage
-- Define function to call when the RemoteEvent is fired
remoteEvent.OnServerEvent:connect(function(player, turnOnForceField)
-- Check to make sure the player has a character model (if
-- not then no need to ForceField)
local character = player.Character
if character then
if turnOnForceField then
-- If turnOnForceField then make a new ForceField and give
-- it to the character
local forceField = Instance.new("ForceField")
forceField.Name = "AdForceField"
forceField.Parent = character
else
-- If not turnOnForceField then remove the ForceField
-- from the character
local forceField = character:FindFirstChild("AdForceField")
if forceField then
forceField:Destroy()
end
end
end
end)
-- LocalScript
-- Bind function to when video ad finishes. Call RemoteEvent to
-- remove the player's ForceField
game:GetService("AdService").VideoAdClosed:connect(function()
game.ReplicatedStorage.ForceFieldEvent:FireServer(false)
end)
-- Define function that will play ad and call RemoteEvent to give
-- player a ForceField
local function playAd()
game:GetService("AdService"):ShowVideoAd()
game.ReplicatedStorage.ForceFieldEvent:FireServer(true)
end
-- Binding playAd to the mouse click of a text button. Does not have
-- to be like this in your game, simply call playAd when you want
-- an ad to be played
script.Parent.MouseButton1Click:connect(playAd)
What is Adservice because if i go to the Roblox wiki and click it it brings up a blank webpage: