Part isnt detecting touch after being moved from replicated storage

my script detects a msg from the player firing an event that tells a local script to make the part appear for the client. but when it does appear. it doesnt work when touched.

local script (rep storage)
 script.Parent.OnClientEvent:Connect(function(plr)
 	local glob = game.ReplicatedStorage.Globs["Deep Sea Glob"]
 	glob.Parent = workspace.Globs["Main Island"]
	script.Parent.Sound:Play()
 	--glob.Sound:Play()
 end)

touch script (in the part)

 CD = false
 BS = game:GetService("BadgeService")

 script.Parent.Touched:Connect(function(Hit)
	print("yo1")
	if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil and not CD then
		print("yo")
		local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if plr ~= nil then
			task.wait(1)
			BS:AwardBadge(plr.UserId, script.Parent.BadgeId.Value)
				plr.PlayerGui.Dex.Main.Glob.Obtained = true
				plr.PlayerGui.Dex.GlobMains.GlobMain.Description.Text = 
                                script.Parent.Description.Text
				CD = true
				task.wait(1)
				CD = false
		end		
	end
end)

server script (sss)


local plrs = game:GetService("Players")
local canactivate = true

plrs.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "/e INTHESAND" and canactivate then
			game.ReplicatedStorage.Events.DeepSea:FireClient(plr)
			canactivate = false
			task.wait(3)
			canactivate = true
		end
	end)
end)

i tried using print to debug but it would never print anything

If the script in the part is local, then convert it to a normal script and set the property RunContext to local. But I don’t think this is the issue.

Below, I’ll assume it’s a server script
As you know, normal scripts run on the server, and the touch part script won’t run because it’s a server script inserted by the client. So the server doesn’t know it exists and so will not run it.

Solution? Do what I said in the first paragraph or move the code in the touch script to the local script.

What RunContext means

RunContext basically sets where the script will run. If set to legacy (recommended) then it will run like a normal server script and run in a few places such as Workspace and ServerScriptService. If set on server, it runs as a server script almost anywhere in the game, including ServerStorage. If set to client, it runs almost anywhere in the game as a client script. LocalScripts are basically just a script with “Legacy” RunContext for the client (anywhere where it’s a descendant of the player or its character).

1 Like

now i need to award the player the badge (which cant be done in local scripts,) how will i award the player the badge?
when i fire a server event, my server script that i made to give them the badge doesnt activate.

Can I see the updated code to see what might be wrong?

Ended up solving it myself but you did really help! Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.