Local script not working in newly cloned model

Hello, I am working on a fighting game, but my local script in a part thats in a cloned model will not print or do anything. I am trying to make a money collect script .Here is the script’s code:

print(“Script found”)
local Bill = script.Parent
local player = game.Players.LocalPlayer

Bill.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
player.leaderstats.money.Value = player.leaderstats.money.Value + 1
hit.Parent:Destroy()
end
end)

I have tried to look through dev forums, change the local script to a normal script. And change the location and model. But nothing has helped. The model is also cloned by a normal script, and the script seems to still appear when playing, but it won’t run. Does anybody know the solution?

because youre trying to get the localplayer in a serverscripts which they dont have

print("Script found")
local Bill = script.Parent

Bill.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		player.leaderstats.money.Value = player.leaderstats.money.Value + 1
		hit.Parent:Destroy()
	end
end)

The money collect script is a local script

What is the parent, other than the model, (highest ancestor, rather) of the Local Script? If it’s located anywhere in workspace, it will not run.

Oh okay, thank you. I will try that.

Remember,

LocalScripts can only run in:

  • StarterPack (tools and whatnot)
  • StarterGui (including GUI elements themselves, obviously)
  • StarterPlayerScripts
  • StarterCharacterScripts
  • ReplicatedFirst

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