I tried this and it worked in Play Solo mode, but it doesn't work in online mode. What needs to be changed?

--Scripted by Aceta.

local sP = script.Parent --Defining the script's Parent.
local debounce = true

function onTouch(hit)
local hum = hit.Parent:FindFirstChild('Humanoid')
if hit and hum and debounce == true then
debounce = false
local cam = Workspace.CurrentCamera	 --Defining the player's camera.
local brick = Instance.new('Part', Workspace)	--Creating the brick.
brick.Anchored = true
brick.Material = ('DiamondPlate')
brick.BrickColor = BrickColor.new('Bright red')
brick.Transparency = 0.1
brick.Size = Vector3.new(5,6,1)
brick.Name = ("My custom brick")
brick.Parent = cam	
print("Brick assigned to player")	 --Making sure everything works.
end
end

sP.Touched:connect(onTouch)

2 comments

0

Script objects inside of local objects will not run. In addition, local objects do not receive Touched events. Because you haven't provided more context, I cannot offer any further advice

0

I'm trying to make a localbrick spawn when a player touches a brick.