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

How do I make a function play using an 'if' statement?

Asked by 4 years ago

Im trying to make a rickroll prank game (yea yea)

But the script to play 'Never Gonna Give You Up' isn't working. Im fairly new to if statements myself, sorry if I seem stupid to you.

Script:

local Player = game:GetService("Players").LocalPlayer

function RickRoll()
    game.Workspace.Sound.Play()
end

if Player.PlayerAdded then
    wait(5)
    RickRoll()
end

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The PlayerAdded signal is home to the Players Service, you’re trying to reference it through a Player Object. It shouldn’t necessarily be used as a conditional either though, since it’s an RBXScriptSignal you can simply just run the code as an event:

local Players = game:GetService("Players")

local Sound = workspace:WatForChild("Sound")

local function RickRoll()
    wait(5); Sound:Play()
end

Players.PlayerAdded:Connect(RickRoll)
0
Sorry for the late respose but I figured it out myself, lol. Have some free rep tho TotalElevation 45 — 4y
Ad

Answer this question