I need help creating a script that works client side only

  1. I need help to make a script that, when clicked from a player, clones a group, spawns it in the workspace, and works on client side only.

  2. The script already works, but if i put it on a local script it doesn’t, i tried in many ways

  3. I tried to put it inside a part, in the server script service and changing it up a bit.

This is my current script:

local players = game:GetService("Players")

local part = script.Parent

local renderableClone = nil

part.ClickDetector.MouseClick:Connect(function(player)
	if (player.Character.Head.Position - part.Position).unit:Dot((part.CFrame.lookVector)) > 0 then
		print("Script started")
		if renderableClone then
			print("Condition satisfied")
			renderableClone:Destroy()
			renderableClone = nil
		else
			print("Cloning renderable")
			local renderable = ReplicatedStorage:WaitForChild("renderable")
			renderableClone = renderable:Clone()
			renderableClone.Parent = workspace
			renderableClone.CFrame = part.CFrame
		end
	end
end)

So basically inside a part, i have 2 scripts, one that changes his property “can collide” on and off when clicked, and the other is the one i’ve written above.
When a player clicks the part, while standing in front of it, it makes the player able to pass trough it and spawns a group, but if you click it from the other side it doesn’t work, the other scripts continue to change the “can collide” on and off, so it’s like a working door, but the group only appears and disappears when you click the part from the front. So the player can’t see the group disappear and appear, optimizing the game.

Now my problem is, making this script client side only, where do i need to put my local script? Do i just need to copy this one and put it somewhere? I can’t find the solution, thanks.

1 Like

Mind sending us a video on the issue so that we can see it clearly. Also can you show the layout of where the click detector is?

It is a bit strange how it works when you are in front of the click detector but not when your at the side. Is there any type of brick or something in the way stopping it from being clicked?

local script is working only inside player. (inventory, character, gui)

As RonClon has mentioned, LocalScripts don’t work inside workspace/parts.

You have two options:

  1. Move the LocalScript to either StarterPlayer.StarterPlayerScripts or StarterPlayer.StarterCharacterScripts
  2. Create a Script, copy the code into it and change the RunContext to “Client”. This will make it behave exactly like a LocalScript but it will work anywhere, including your Part.
4 Likes

This fixed my problem, i was working all day and there was a feature i didn’t know about, thank you so much.

1 Like

also, im not the FoxBlox xd

1 Like

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