Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why is the script source altered mid-game?

Asked by
appxritixn 2235 Moderation Voter Community Moderator
4 years ago
Edited 4 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:

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!

0
Are you using Team Create? NotedAPI 810 — 4y
1
Yes, however, I am the only one who ever alters scripts. appxritixn 2235 — 4y
1
@oCrxptic That's why. Team Create has a history of things like this and scripts not saving properly. NotedAPI 810 — 4y
1
Ok. I will look into that appxritixn 2235 — 4y

1 answer

Log in to vote
1
Answered by 2 years ago

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

Ad

Answer this question