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

Cloning a part with a string value does not work?

Asked by
hokyboy 270 Moderation Voter
3 years ago

So what I wanted to do is create a data store that holds a string value. with that string value, it clones the Grimoire which belongs to that string value with a string i tried doing this however I get this error

ServerScriptService.ATTACKS.UpdatedAttackScript.GrimoireActivation:16: attempt to call a nil value

Grimoire Activation Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventFolder = ReplicatedStorage:WaitForChild("EVENTS")
local Remote = EventFolder.ActivateGrimoire

function GetGrimoire(player)
    local Char = player.Character
    local Hurmp = Char.HumanoidRootPart
    local DataFolder = player.Data
    local Grimoire = DataFolder.Grimoire
    local GrimoireName = Grimoire.Value

    if GrimoireName == "None" then

    else
        warn(GrimoireName)
        local GrimoireFolder = script..GrimoireName:Clone()
        local NewGrimoire = Grimoire.Open
        NewGrimoire.Parent = workspace

    end
end

EventFolder.ActivateGrimoire.OnServerEvent:Connect(function(Player)
    GetGrimoire(Player)
end)

DataStore

-- Datastore Version 1

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("AA99")

game.Players.PlayerAdded:Connect(function(player)

    local datafolder = Instance.new("Folder")
    datafolder.Name = "Data"
    datafolder.Parent = player

    local Grimoire = Instance.new("StringValue")
    Grimoire.Name = "Grimoire"
    Grimoire.Value = "FireGrimoire"
    Grimoire.Parent = datafolder 
end)

game.Players.PlayerRemoving:Connect(function(player)

    local sucess, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-Grimoire",player.Data.Grimoire.Value)
    end)
    if sucess then
        warn("Data saved")
    else
        print("Eror Saving Data")
        warn(errormessage)
    end

end)

1 answer

Log in to vote
1
Answered by 3 years ago
-- grimoire code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventFolder = ReplicatedStorage:WaitForChild("EVENTS")
local Remote = EventFolder.ActivateGrimoire

function GetGrimoire(player)
    local Char = player.Character
    local Hurmp = Char.HumanoidRootPart
    local DataFolder = player.Data
    local Grimoire = DataFolder.Grimoire
    local GrimoireName = Grimoire.Value

    if GrimoireName == "None" then

    else
        warn(GrimoireName)
        local GrimoireFolder = script:WaitForChild(GrimoireName):Clone() -- you added an extra "." and forgot to use waitforchild/findfirstchild
        local NewGrimoire = Grimoire.Open
        NewGrimoire.Parent = workspace

    end
end

EventFolder.ActivateGrimoire.OnServerEvent:Connect(function(Player)
    GetGrimoire(Player)
end)


-- datastore code


--[[ i didnt really see any errors here because you are storing the grimoire value correctly (as a string), if the (player.Data.Grimoire.Value) is not a string the code above will still error ]]--

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("AA99")

game.Players.PlayerAdded:Connect(function(player)

    local datafolder = Instance.new("Folder")
    datafolder.Name = "Data"
    datafolder.Parent = player

    local Grimoire = Instance.new("StringValue")
    Grimoire.Name = "Grimoire"
    Grimoire.Value = "FireGrimoire"
    Grimoire.Parent = datafolder 
end)

game.Players.PlayerRemoving:Connect(function(player)

    local sucess, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-Grimoire",player.Data.Grimoire.Value)
    end)
    if sucess then
        warn("Data saved")
    else
        print("Error Saving Data") -- minor spelling mistake
        warn(errormessage)
    end

end)
0
yeah i forgot about findfirstchild cause i was tired hokyboy 270 — 3y
Ad

Answer this question