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

How to make a cloned model's script work in-game?

For some reason, whenever I clone a model into the Workspace (from ReplicatedStorage), the player detection script works in Studio, but not in-game. I've tried inputting the code into a local script, but it stops working entirely.

Here's the code:

local floor = script.Parent
local light = script.Parent.Parent.MainLight.SurfaceLight
player = game.Players.LocalPlayer
ambience = game.Lighting.Ambient
local debounce = false

s1=game.Workspace.Scream1
s2=game.Workspace.Scream2
s3=game.Workspace.Scream3

function Caught(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if h ~= nil then
		h.WalkSpeed= 0
		
			if (h ~= nil) then
		h.WalkSpeed = 0
		game.Workspace["In-Game Music"]:Stop()
		wait(2.5)
		game.Workspace.Alarm:Play()
		ambience = Color3.new(255/255,255/255,255/255)
		script.Parent.Parent.MainLight.Material = "Neon"
		light.Enabled = true
		wait(1.5)
		s1:Play()
		s2:Play()
		wait(5)
		player.PlayerGui.GameRecap.Enabled = true
		player.PlayerGui.GameRecap.EP.LVL.L1.LoseLvl.Visible = true
		wait(4)
		game.Workspace.Alarm:Stop()
		ambience = Color3.new(30/255,30/255,30/255)
		game.Workspace["In-Game Music"]:Play()	
		wait(1)
	debounce = false	
	end
	end
	end

script.Parent.Touched:connect(Caught)

1 answer

✓ Accepted answer

This doesn’t work because it is a local script that you are cloning into workspace. Local scripts can only run when they are a descendant of something that is individual to each player, such as their gui or backpack. You should convert this to a server script and use remote events to edit the player’s guis on the client. To get the player from their character to fire this event, you can go:

local plr = game.Players:GetPlayerFromCharacter(part.Parent)

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