Why is the script source altered mid-game?
Asked by
5 years ago Edited 5 years ago
I have found an error when making tools for my game. I am making a wizard game, which uses potions. When the player finishes making their potion, I want to put the potion into the player's backpack; however, when the potion's script (I have tried both a local script, and a server script) is always reset back to the default source:
My question in simple terms is this: Why does the source get reset when I add the potion into the player's backpack (from ServerStorage)?
My second question is this: Does the tool have to be in ReplicatedStorage in order for the script not to be reset, or am I just experiencing a bug?
The code I have in my (now local) script is as follows:
3 | local potionType = script.Parent:WaitForChild( "TYPE" ).Value |
5 | script.Parent.Activated:Connect( function () |
6 | game.ReplicatedStorage.Potions.Actions.Drank:FireServer(potionType) |
The code is meant to be called when the player wants to drink the potion they have brewed.
Edit:
I thought that I would include the code in which I change the potion's parent, and in a way, the script's:
1 | game.ReplicatedStorage.RemoteEvents.PotionFinished.OnServerEvent:Connect( function (player) |
2 | local potionType = script.Parent:FindFirstChild( "Potion Type" ).Value |
3 | if potionType = = nil or potionType = = "" then |
6 | local potion = game.ServerStorage.Potions [ potionType.. " Potion" ] :Clone() |
7 | potion.Parent = player.Backpack |
I did not want to add the ENTIRE script, as it is fairly lengthy.This script is inside of the cauldron.
If you wish for me to provide more information, please leave a comment with the specific information you are requesting, and I will update the question.
As always, all help is appreciated. Thank you in advance!