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

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

Asked by 6 years ago

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.

0
Don't ask the same question more than once. mudathir2007 157 — 6y
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. mudathir2007 157 — 6y
0
have a local script listening for a remote event play the sound in the Player's playergui instead of trying to convert it Vulkarin 581 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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()
Ad

Answer this question