Code not running

Hi! I have no idea why this code isn’t running. It won’t print at all, nothing is running. It is fairly simple

Code
print("test1")
-- Variables
local Player = script.Parent.Parent
local TemShop = game.Workspace.TemShop
local Button = game.Workspace.TemShop.InteractButton
local ClickDetector = game.Workspace.TemShop.InteractButton.ClickDetector
local ShoppingGui = game.Lighting.ShoppingGui:Clone()
-- Clicked Code
ClickDetector.MouseClick:Connect(function(Player)
	Player.Character.HumanoidRootPart.CFrame = TemShop.PlayerShopPosition.CFrame
	Player.Character.HumanoidRootPart.Anchored = true
	ShoppingGui.Parent = Player.Character.Head
end)
Information on Code
  • Server Script
  • Parented to the StarterPlayerScripts

Is this a script or a local script and where is it located?
edit. Nvm, you need a local script on the client for the script to run, regular scripts wont run

1 Like

Please read the “Information on Code” section.

Put the code in ServerScriptService

Why? This is meant to run on certain players. What would the benefit be? I know how to convert it to .PlayerAdded.

Then you should be using a LocalScript.

Yes but it’s affects are meant to be seen by all.

Affects done in StarterPlayerScripts cannot be seen by all.

remote events? have you not used that before?

Yes. That is why it is a server script.

Put it in serverscript service it would work perfectly fine as you are receiving the player through the mouse click function

For that you’ll need RemoteEvents.

Like, there’s no need for it to run from client to server. ClickDetectors work Serverside I’m fairly sure.

Okay, but can the issue with it being in the PlayerScripts be explained?

only local scripts can run on a client, if you want the client to talk to the server, use a remote event.

1 Like

What do you mean? Does the player count as like the client in Instance form?

I believe that’s correct, so if you replace your code with the following and put the Script in ServerScriptService, you should get the desired effect.

game.Workspace.TemShop.InteractButton.ClickDetector.MouseClick:Connect(function(Player)
	Player.Character.HumanoidRootPart.CFrame = TemShop.PlayerShopPosition.CFrame
	Player.Character.HumanoidRootPart.Anchored = true
	game.Lighting.ShoppingGui:Clone().Parent = Player.Character.Head
end)
1 Like