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

I want that if a player touches a part, it plays a certain sound. What is wrong with my script?

Here is my script inside the workspace:

local replicatedstorage = game:GetService("ReplicatedStorage")
 remote = replicatedstorage:WaitForChild("RemoteEvent")
local players = game:GetService("Players")



	local blokje = game.Workspace.Aangeraakt
	blokje.Touched:connect(function(otherpart)
		if otherpart.Parent.Humanoid then
			local player = otherpart.Parent:GetPlayerFromCharacter
			remote:FireClient(player)
		end
	end)

Here is my localscript inside the starterplayerscripts:

local players = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local player = players.LocalPlayer
local remote = replicatedstorage:WaitForChild("RemoteEvent")
local playergui = player.PlayerGui
local sound = Instance.new("Sound", playergui)
sound.SoundId = "rbxassetid://1280470"

local function SoundPlay()
	local aangerakt = game.Workspace.Aangeraakt
	aangerakt.Touched:connect(function(otherpart)
		if otherpart.Parent.Humanoid then 
			sound:Play()
		end
		
	end)
	
end

remote.OnClientEvent:connect(SoundPlay)

The error from Roblox Studio: Workspace.Aangeraakt.Music:11: function arguments expected near 'remote'

3 comments

0

and the sound can only be heared by the localplayer who activated it

0

If only the localplayer can hear it, why don't you just create the sound in the localscript? Nobody would be able to hear it.

0

You used the GetPlayerFromCharacter() function improperly

1 answer

✓ Accepted answer

Try this one! You wrong used :GetPlayerFromCharacter()

local replicatedstorage = game:GetService("ReplicatedStorage")
 remote = replicatedstorage:WaitForChild("RemoteEvent")
local players = game:GetService("Players")



    local blokje = game.Workspace.Aangeraakt
    blokje.Touched:connect(function(otherpart)
        if otherpart.Parent.Humanoid then
            local player = otherpart.Parent:GetPlayerFromCharacter()
            remote:FireClient(player)
        end
    end)

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