Hello,
I am working on an announcement GUI. So you are able to announce things server wide. I have that whole system done and its working perfectly. I want to add another sections for Presets. This is so you don’t have to type the same things over and over again and you can announce or save them. I have the announcing part of it done but I am having troubles with the saving part? Maybe I am doing something wrong? Can you save text in datastores?
SERVER SCRIPT:
--// Datastore
local DatastoreService = game:GetService("DataStoreService")
local Save1 = DatastoreService:GetDataStore("Save1")
local Save2 = DatastoreService:GetDataStore("Save2")
local Save3 = DatastoreService:GetDataStore("Save3")
--// SAVES AND SAVING
game.Players.PlayerAdded:Connect(function(Player)
local SaveOne = Save1:GetAsync("UserId="..Player.UserId) or nil
local SaveTwo = Save2:GetAsync("UserId="..Player.UserId) or nil
local SaveThree = Save3:GetAsync("UserId="..Player.UserId) or nil
Event2:FireClient(SaveOne, SaveTwo, SaveThree)
end)
Event2.OnServerEvent:Connect(function(Player, SlotToSave, WhatToSave)
if SlotToSave == 1 then
Save1:SetAsync("UserId="..Player.UserId, WhatToSave)
elseif SlotToSave == 2 then
Save2:SetAsync("UserId="..Player.UserId, WhatToSave)
elseif SlotToSave == 3 then
Save3:SetAsync("UserId="..Player.UserId, WhatToSave)
else
print("Not a slot.")
end
end)
EDIT: The error is on the server script, “Unable to cast value to Object” on “Event2:FireClient(SaveOne, SaveTwo, SaveThree)”
CLIENT SCRIPT:
--// Save Buttons
local SaveOne = script.Parent.Save1
local SaveTwo = script.Parent.Save2
local SaveThree = script.Parent.Save3
--// Text Inputs
local One = script.Parent.One.Message
local Two = script.Parent.Two.Message
local Three = script.Parent.Three.Message
local SaveEvent = game.ReplicatedStorage:WaitForChild("AnnouncementEvents"):WaitForChild("Save")
--// SAVES
local function Save(Slot)
if Slot == 1 then
SaveEvent:FireServer(Slot, One.Text)
elseif Slot == 2 then
SaveEvent:FireServer(Slot, Two.Text)
elseif Slot == 3 then
SaveEvent:FireServer(Slot, Three.Text)
elseif Slot >= 4 then
print("Not a slot")
end
end
SaveEvent.OnClientEvent:Connect(function(LoadedOne, LoadedTwo, LoadedThree)
One.Text = LoadedOne
Two.Text = LoadedTwo
Three.Text = LoadedThree
end)
SaveOne.Activated:Connect(function()
Save(1)
end)
SaveTwo.Activated:Connect(function()
Save(2)
end)
SaveThree.Activated:Connect(function()
Save(3)
end)
Thanks for helping!