How can you delete a local script thats inside the players character with a server script? Would you have to use :Destroy()? or something else? since i tried :Destroy() and it didnt seem to work, is there another way to do it?
Yes, since the Localscript is an instance you would use :Destroy()
Yep you can its an instance so either destroy, or there’s a property named enabled you can try to turn that off as well.
it works when i try to destroy a server script but doesnt work when its a local script getting destroyed, why does this happen?
So the local script doesn’t get destroyed, but does the bike:Destroy() work?
Try disabling it instead of destroying it.
its the same for when i want to disable it, it just comes back as nil like its not even there when it clearly is
bike:Destroy() works but the destroying of the local script doesnt work
Make sure the local script is in StarterCharacterScripts and not StarterPlayerScripts
I put the placed both the bike and the script inside the players character and the script destroying still doesnt seem to work
I think i know why. Earlier in the script you’re already defining ChosenAbility and then trying to say the local script is FindFirstChild(ChosenAbility.Name)
Instead do
local ability = char:FindFirstChild(“ChosenAbility”)
Or you can change the name of the variable called ChosenAbility
Thats also probably why its saying you’re attempting to index nil.
I removed the .Name in the chosen ability pathway variable and still got the same error with a new one
Look, here is how i think you can fix your problem:
First, change the variable to something like
local CurrentAbility = Abilities:FindFirstChild("CurrentAbility").Value
then, change the local script variable to
local ability = char:FindFirstChild("ChosenAbility")
This is because whenever you use a FindFirstChild
or WaitForChild
you always use parenthesis and then quotation marks. Like so:
local example = game.ReplicatedStorage:FindFirstChild("Example").Value -- The .Name, or .Value or whatever it may be always comes after the ("")
A server script normally replicates everything for every connected client. If you delete only one local script from one specific client, you must use a RemoteEvent to go from the server to the client.
To do this, fire the RemoteEvent from the server on the event when you want it to delete the script.
RemoteEvent:FireClient()
Then, on the receiving client, make it find the script & delete it afterward!
RemoteEvent.OnClientEvent:Connect(function()
local Player = game.Players.LocalPlayer
local LocalScript = Player:FindFirstChildOfClass("LocalScript"):GetFullName("LocalScript")
LocalScript:Destroy()
end)
I sent a remote event to the client to destroy the script, and got this error
this is the server script
this is the client script
shouldn’t the local script be `
local LocalScript = script.Parent
or should it be:
local char = player.Character
local LocalScript = char.LocalScript
But when i use that, it only makes a pathway to one specific thing all the time and i dont want that, in my case the player can change the current cart/ current ability value in my game and it wont always be the same so when i the local variable instead of quotation marks it can adapt to its changed value, for example the current cart value could be a bike and so it spawns a bike or the current cart value could be a sleigh and it spawns a sleigh
Ah, my bad. i didn’t know the context, sorry!