Stack end error/ code not working without an error?

Hey, new scripter here. So I am trying to add a model/ keys to a local player upon the part being touched but it does not seem to be working and I don’t know the clear error in this case. Please help, the code is below, as well as what tends to be the error message??

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local keyModels = game.Workspace:WaitForChild("KeyModels")
local keys = game.ServerStorage:WaitForChild("Keys")

-- key models
local starterKeyModel = keyModels:FindFirstChild("StarterKeyModel")
local greenZoneKeyModel = keyModels:FindFirstChild("GreenZoneKeyModel")

-- actual keys
local starterKey = keys["Starter Key"]
local greenZoneKey = keys["Green Zone Key"]

local function destroyParts(parts)
	for _,v in pairs(parts) do

local function starterKeyTouched(hit)
	if hit and hit.Parent.Name == player.Name then
		local keyClone = starterKey:Clone()
		keyClone.Parent = player.Backpack

local function greenZoneKeyTouched(hit)
	if hit and hit.Parent.Name == player.Name then
		local keyClone = greenZoneKey:Clone()
		keyClone.Parent = player.Backpack


1 Like

check that the two buttons in output say “All Messages” and “All Contexts”, you might’ve accidentally disabled the Error context :smile:

1 Like

I have check marks in all of the checkboxes for the dorpdowns for all messages and alll contexts


can I first question why is “game.Players.LocalPlayer” and “game.ServerStorage” is in the same script?

its a local script. the serverstorage is where the models are stored in. I am trying to clone that only to local player and destroy it only to that local player

exactly the serverstorage is empty for the local scripts as the name “SERVERstorage”
use replicatedstorage instead

research says serverstorage errors when used in local, thats your problem

that seems to work for that script such that I don’t get the stack ended error. I got another local script failing now :sob:. Do you mind providing a crashcourse on local script such as where it can or cannot be used or just general tips that you have? It is much appreciated! it took me 7 hrs last time I worked with local scripts to figure out that there are only a specific locations that it can be used in

local scripts are what you use to listen to the inputs of the player and inform the server the player wants to do something

the other thing is player character physics. As the character physics are controlled by the computer of the player, doing most things like playing animations, setting walkspeed, setting humanoid states (doing so cannot even work for most of em) in the server is not ideal and should be done in local instead

if its still confusing I can explain further.

I see. I had a general idea but this reply seems to widen it. Thank you!

I see you doing everything in the local, which will not work here are more tips for that:

if you dont know what a RemoteEvent or a RemoteFunction is I highly suggest learning it as it can teach more on how to use localscripts and make you understand local-server communication more

I am aware of remote events and server and client communications. But no harm in bordering up my knowledge! Thanks again!

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