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

How would I go about turning a regular script into a local script?

For example this script:

local Players = game:GetService("Players")
local getPlayerFromCharacter

getPlayerFromCharacter = function(model)
    local plr = Players:GetPlayerFromCharacter(model)

    if plr then return plr end 
end

script.Parent.Touched:Connect(function(hit)
    local player = getPlayerFromCharacter(hit.Parent)

    if player then
        script.Parent.Sound1.Volume = 1
        script.Parent.Sound1:Play()
    end
end)

I want to turn it into a local script since I only want a single player to hear the sound (this script plays a sound on brick touch) instead of the entire server.

What makes a local script different than a regular script in terms of coding?

Sorry if this question seems simple, i'm pretty new at scripting and I tried googling it but I just got more confused.

3 comments

0

Don't ask the same question more than once.

0

A local script runs in the client side and only the client can use the it like Local Parts. You can access Local Player by game.Players.LocalPlayer but a server script you need to find other ways.

0

have a local script listening for a remote event play the sound in the Player's playergui instead of trying to convert it

1 answer

Try this local script in a brick:

local player = game:GetService("Players").LocalPlayer
local click = script.Parent.ClickDetector
local Sound1 = script.Parent.Sound1 -- Put your sound in the brick
local Mouse = player:GetMouse()

Mouse.Button1Down:Connect(function(play)
	if play then script.Parent.Sound1:Play() 
	end
end)

game.Workspace.Part.ClickDetector.MouseClick:connect()

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