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
v:Destroy()
end
end
local function starterKeyTouched(hit)
if hit and hit.Parent.Name == player.Name then
local keyClone = starterKey:Clone()
keyClone.Parent = player.Backpack
starterKeyModel:Destroy()
end
end
local function greenZoneKeyTouched(hit)
if hit and hit.Parent.Name == player.Name then
local keyClone = greenZoneKey:Clone()
keyClone.Parent = player.Backpack
destroyParts(greenZoneKeyModel:GetChildren())
end
end
starterKeyModel.Touched:Connect(starterKeyTouched())
greenZoneKeyModel:FindFirstChild("Sphere.001_Sphere.002").Touched:Connect(greenZoneKeyTouched())
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
that seems to work for that script such that I don’t get the stack ended error. I got another local script failing now . 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
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