Please bare in mind than I’m still quite the beginner. Below I have included some scripts that I believe should work in StarterPlayerScripts but only work in StarterCharacterScripts except they only work sometimes.
local part = game.Workspace.congrations
local pictures = {"http://www.roblox.com/asset/?id=5575514630", "http://www.roblox.com/asset/?id=12972782701"}
local ids = pictures[math.random(1,#pictures)]
part.Decal.Texture = pictures[math.random(1,#pictures)]
this script is meant to display one of those random decals on a part.
local sound = game.Workspace.congrations.Sound
local debounce = true
local bg = game:GetService("SoundService").Sound
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
if debounce == true then
bg:Stop()
sound:Play()
debounce = false
end
end)
This script is meant to play a sound when a part is touched.
I’m not quite sure if these scripts need a specific way to reference workspace or anything, so please let me know!
If your game has the StreamingEnabled property of workspace enabled, it will take abit for instances in workspace to be replicated to the player upon joining, so you will need to use WaitForChild when referencing instances from starterplayerscripts.
local part = game.Workspace:WaitForChild("congrations")
local pictures = {"http://www.roblox.com/asset/?id=5575514630", "http://www.roblox.com/asset/?id=12972782701"}
local ids = pictures[math.random(1,#pictures)]
part.Decal.Texture = pictures[math.random(1,#pictures)]
local sound = game.Workspace:WaitForChild("congrations").Sound
local debounce = true
local bg = game:GetService("SoundService").Sound
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
if debounce == true then
bg:Stop()
sound:Play()
debounce = false
end
end)
PlayerScripts is a container object located inside Player objects within the Players game service. It is created automatically when a player joins the game. Its main purpose is to contain LocalScripts copied from the StarterPlayerScripts container within the StarterPlayer game service, which happens once upon creation. Descendant LocalScripts of PlayerScripts will run code on the client of the Player.
The StarterCharacterScripts class stores scripts to be parented in a player’s Player.Character, when they spawn.
A player spawns after they are join thus giving time for objects in workspace to load in.