How do I go about making this script happen locally, and not to all players

Hey! I have this script that executes a sequences of actions once you click on the part, the issue is I want it to happen locally for each player, meaning the code will execute for a player that clicks it, but for other players around them, nothing happens until they also click it.

I’ve tried running it as a localscript, but I assume it cant call certain things that the normal script could.

local smoke = part:FindFirstChildOfClass("Smoke")
local sound = part:FindFirstChildOfClass("Sound")
local decal = part:FindFirstChildOfClass("Decal")

local function onClicked()
	if sound then
	sound:Play()
	end

	if smoke then
		smoke.Enabled = true
	end

	if decal then
		decal:Destroy()
	end
	
	wait(1.5)
	if smoke then
		smoke.Enabled = false
	end

	part.CanCollide = false
	
end
if part:FindFirstChildOfClass("ClickDetector") then
	part.ClickDetector.MouseClick:Connect(onClicked)
end
1 Like

This all looks like stuff that can run in a local script. If you have other server-based things that need to run, then use a RemoteEvent.

1 Like

that’s only in the case of indexing serverside things like… SSS AKA ServerScriptService and SS AKA ServerStorage local scripts cannot Index these areas*

Edit: also your local script will not run outside a character

1 Like

I tried to run it in a LocalScript in the same spot, but none of the things under onClicked() happen.

1 Like

I originally had it as just a script, i’m just wondering if theres anyway to get this to work per player via something like RemoteEvents or something.

LocalScripts can’t run inside Workspace so you should have it preferably inside StarterPlayerScripts where you’d reference the ClickDetector in the script.

2 Likes

Thank you! I moved the code to a LocalScript in StarterPlayerScripts, but its still disappearing for everyone in the server. Any clue on how to actually get it working locally?

local guy = nil
repeat
	guy = game.Workspace.littleThingsGuys:FindFirstChild("glumpy")
	wait(0.1)
until guy

print('found guy')
local smoke = guy:FindFirstChild("Smoke")
print('found smoke')
local sound = guy:FindFirstChild("Sound")
print('found sound')
local decal = guy:FindFirstChild("Decal")
print('found decal')

local function onClicked()
	if sound then
		sound:Play()
	end

	if smoke then
		smoke.Enabled = true
	end

	if decal then
		decal:Destroy()
	end

	wait(1.5)
	if smoke then
		smoke.Enabled = false
	end

	guy.CanCollide = false

end
if guy:FindFirstChildOfClass("ClickDetector") then
	guy.ClickDetector.MouseClick:Connect(onClicked)
end
local guy = nil
repeat
	guy = game.Workspace.littleThingsGuys:FindFirstChild("glumpy")
	wait(0.1)
until guy

print('found guy')
local smoke = guy:FindFirstChild("Smoke")
print('found smoke')
local sound = guy:FindFirstChild("Sound")
print('found sound')
local decal = guy:FindFirstChild("Decal")
print('found decal')

local function onClicked(player)
    if player ~= game.Players.LocalPlayer then return end -- the local player didn't click this, so ignore it
	if sound then
		sound:Play()
	end

	if smoke then
		smoke.Enabled = true
	end

	if decal then
		decal:Destroy()
	end

	wait(1.5)
	if smoke then
		smoke.Enabled = false
	end

	guy.CanCollide = false

end
if guy:FindFirstChildOfClass("ClickDetector") then
	guy.ClickDetector.MouseClick:Connect(onClicked)
end

Try checking if the person who clicked the ClickDetector is the local player?

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