Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the script source altered mid-game?

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:

print("Hello World!")

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:

-- made by oCrxptic

local potionType = script.Parent:WaitForChild("TYPE").Value

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.Potions.Actions.Drank:FireServer(potionType)
end)

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:

game.ReplicatedStorage.RemoteEvents.PotionFinished.OnServerEvent:Connect(function(player)
	local potionType = script.Parent:FindFirstChild("Potion Type").Value
	if potionType == nil or potionType == "" then
		potionType = "mundane" -- Has no effects, error.
	end
	local potion = game.ServerStorage.Potions[potionType.." Potion"]:Clone()
	potion.Parent = player.Backpack
end)

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!

4 comments

0

Are you using Team Create?

1

Yes, however, I am the only one who ever alters scripts.

1

@oCrxptic That's why. Team Create has a history of things like this and scripts not saving properly.

1

Ok. I will look into that

1 answer

✓ Accepted answer

NotedAPI said it has something to do with team create, so imma go with that

This discussion is preserved as it was. New answers, comments, and votes are closed.