Hi. I’m developing cardgame, and having problems.
Scripts here.
--module to store cards
local allCards= {
{
Name = "A",
Type = "Creacher",
Rarity = "Common",
Habitat = "Forest",
Cost = 2,
Health = 2,
Attack = 2,
Defense = 0,
Shield = false
},
{
Name = "B",
Rarity = "Common",
Habitat = "Forest",
Cost = 1,
Type = "Creacher",
Health = 1,
Attack = 1,
Defense = 0,
Shield = true
},
{
Name = "C",
Rarity = "Rare",
Habitat = "Forest",
Cost = 4,
Type = "Creacher",
Health = 3,
Attack = 2,
Defense = 1,
Shield = false
},
{
Name = "D",
Rarity = "Legend",
Habitat = "Savvana",
Cost = 7,
Type = "Creacher",
Health = 6,
Attack = 4,
Defense = 1,
Shield = true
}}
return allCards
--server script
local TP = game:GetService("TeleportService")
local players = game:GetService("Players")
local dStorage = game:GetService("DataStoreService")
local rStorage = game:GetService("ReplicatedStorage")
local sStorage = game:GetService("ServerStorage")
local cards = require(sStorage.AllCards)
local events = rStorage.RemoteEvents
local functions = rStorage.RemoteFunctions
local hands1 = {}
local hands2 = {}
local function useCard()
end
--ドローを指定の回数行う
local function draw(player, number)
local allcards = {}
local drawn = {}
for _, card in pairs(cards) do
table.insert(allcards, card)
end
for i=1, number do
local rnum = math.random(1, #allcards)
local newHand = allcards[rnum]
table.insert(drawn, newHand)
if #hands1 <= 9 then
table.insert(hands1, allcards[rnum])
end
end
print("Card drew")
events.DrawEvent:FireClient(player, drawn)
end
functions.FocusHand.OnServerInvoke = function(pl, i)
print("Focus received")
if pl == hands1.Parent then
if i <= #hands1 then
print("Focus1")
print(hands1[i].Name)
return hands1[i].Name, hands1[i].Type, hands1[i].Habitat, hands1[i].Cost, hands1[i].Rarity, hands1[i].Attack, hands1[i].Health, hands1[i].Defense
else
return nil
end
end
end
--プレイヤーに配列データを設定
players.PlayerAdded:Connect(function(pl)
task.wait(4)
hands1.Parent = pl
print("Player arrived")
for i=1, 3 do
draw(pl, 4)
task.wait(2)
end
end)
--local script
if game:IsLoaded() == false then
game.Loaded:Wait()
end
local players = game:GetService("Players")
local player = players.LocalPlayer
local pGui = player.PlayerGui
local sGui = game:GetService("StarterGui")
local rStorage = game:GetService("ReplicatedStorage")
local cards = rStorage.Cards:GetChildren()
local events = rStorage.RemoteEvents
local functions = rStorage.RemoteFunctions
local battle = pGui:WaitForChild("Battle")
local hands = battle.HandF1.Hands:GetChildren()
local showingCard = false
--画面切り替え時の暗転
local function getDark()
for i=1, 20 do
battle.Dark.Transparency -= 0.05
task.wait(0.06)
end
task.wait(1)
for i=1, 20 do
battle.Dark.Transparency += 0.05
task.wait(0.05)
end
end
events.DrawEvent.OnClientEvent:Connect(function(drawn)
print("Recieved drawevent")
--ドローされたカードを特定
for i=1, #drawn do
for _, card in ipairs(cards) do
if card.Name == drawn[i].Name and #hands <= 9 then
print("Card found")
local newcard = card:Clone()
table.insert(hands, newcard)
newcard.Parent = battle.HandF1.Hands
newcard.Size = UDim2.new(0.15,0,1,0)
continue
elseif card.Name == drawn[i].Name then
print("Too many cards")
local newcard = card:Clone()
newcard.Parent = battle.Grave1
continue
end
end
end
--カード位置の調整
for i=1, #hands do
local d = (1-0.15) / 9
if #hands%2 == 0 then
hands[i].Position = UDim2.new(0.075 + 5*d - #hands/2*d + d*(i - 1), 0, 0.5, 0)
hands[i].ZIndex = 100*i
elseif #hands%2 == 1 then
hands[i].Position = UDim2.new(0.5 - d*(#hands - 1)/2 + d*(i - 1), 0, 0.5, 0)
hands[i].ZIndex = 100*i
end
end
end)
local function showText(Name, Type, Habitat, Cost, Rarity, Attack, Health, Defense)
print("Showing Text")
local page = battle.CardPage
local currentCard
for i=1, cards do
if Name == cards[i].Name then
currentCard = cards[i]
end
end
page.AttackF.AttackValue.Text = Attack
page.DefenseF.DefenseValue.Text = Defense
page.HaelthF.HealthValue.Text = Health
page.HabitatF.HabitatValue.Text = Habitat
page.CostF.CostValue.Text = Cost
page.RarityF.RarityValue.Text = Rarity
local currentImage = Instance.new("ImageLabel")
currentImage.Parent = page.ImageF
currentImage.Size = UDim2.new(1, 0, 1, 0)
currentImage.Image = currentCard.Image
end
for i=1, #hands do
hands[i].Activated:Connect(function(i)
local success, focused = pcall(functions.FocusHand:InvokeServer(i))
if success then
showText(focused)
else
print("Failed to focus on this hand")
end
end)
end
task.wait(1)
sGui:SetCore("ResetButtonCallback", false)
When I ran this, error occured.
23:11:11.141 Player arrived - サーバー - BattleManager:72
23:11:11.142 Card drew - サーバー - BattleManager:45
23:11:11.174 Recieved drawevent - クライアント - GuiManager:46
23:11:11.175 Card found (x4) - クライアント - GuiManager:54
23:11:13.157 Card drew - サーバー - BattleManager:45
23:11:13.191 Recieved drawevent - クライアント - GuiManager:46
23:11:13.191 Card found (x4) - クライアント - GuiManager:54
23:11:15.158 Card drew - サーバー - BattleManager:45
23:11:15.191 Recieved drawevent - クライアント - GuiManager:46
23:11:15.191 Card found - クライアント - GuiManager:54
23:11:15.192 Too many cards (x3) - クライアント - GuiManager:61
23:11:21.757 Focus received - サーバー - BattleManager:52
23:11:21.758 ServerScriptService.BattleManager:55: attempt to compare nil <= number - サーバー - BattleManager:55
23:11:21.758 Stack Begin - Studio
23:11:21.758 Script ‘ServerScriptService.BattleManager’, Line 55 - Studio - BattleManager:55
23:11:21.758 Stack End - Studio
23:11:21.792 ServerScriptService.BattleManager:55: attempt to compare nil <= number - クライアント - GuiManager:120
23:11:21.792 Stack Begin - Studio
23:11:21.792 Script ‘Players.Oceanblue857.PlayerScripts.GuiManager’, Line 120 - Studio - GuiManager:120
23:11:21.792 Stack End - Studio
I want to show cardpage when each card is activated. (This is the objective)
But functions.FocusHand:InvokeServer(i) return nil.
Also, drawn cards don’t fire Activated event.