I'm making a spin system for my magic game. And I need to let a server side script know what magic the player got. So I made a string value called "ChosenMagic", and the script that gives the player a magic will change it's value to the name of the magic. Then a folder that includes all the magics will look at the value and check to see if any of the magics matches that value, if it does then it'll clone it into the players backpack, if not then it'll give off an error. And it gives me this error:
is not a valid member of Folder ReplicatedStorage.Magics Even though the string value's value isn't a space, the script does change it to whatever magic the player got. I don't know why this is happening. Anyways,
EDIT: I changed the local script. And now it gives me this error:
Players.Desmondo1.PlayerGui.Menu.Spinning.Spin.Spinning:83: invalid argument #3 (string expected, got nil) - Client -
Edit again: I fixed that error, but it still gives me the same error as I started off with. (I've updated the code to what it currently is)
Edit once again: The problem was that I was making the value change on the clients side. Hence, only the client can see it. So the server still saw the value as nil. Apparently, you can pass parameters through remote events so by just passing the ChosenMagic parameter through to the server script. I was able to make it work.
Local script
local AlreadyClicked = false
local Amount = 0.003
local LoopTimes = script.Parent.LoopTimes
local YourMagic = script.Parent.Parent.YourMagic
local RS = game:GetService("ReplicatedStorage")
local StringValues = RS.StringValues
script.Parent.MouseButton1Down:Connect(function()
if game.Players.LocalPlayer.Backpack.Spins.Value == 0 then
local NES = script.Parent.Parent.NotEnoughSpins
NES.Visible = true
wait(2)
for i=1, 20 do
NES.BackgroundTransparency = NES.BackgroundTransparency + 0.05
NES.TextTransparency = NES.TextTransparency + 0.05
wait(0.1)
end
NES.Visible = false
NES.BackgroundTransparency = 0
NES.TextTransparency = 0
return
end
if AlreadyClicked == true then
return
--print("AlreadyClicked")
end
AlreadyClicked = true
RS.RemoteEvents.TakeAwaySpins:FireServer()
local Magics = {"Fire","Water","Nature","Void","Wind","Lightning","Curse","Demon","Fire","Water","Nature","Fire","Fire","Water","Nature","Wind","Wind","Wind","Lightning","Fire","Fire","Water","Water","Fire"}
for i=1, 15 do
if LoopTimes.Value == 8 then
Amount = 0.1
end
if LoopTimes.Value == 12 then
Amount = 0.15
end
if LoopTimes.Value == 13 then
Amount = 0.5
end
if LoopTimes.Value >= 14 then
LoopTimes.Value = 0
Amount = 0.003
AlreadyClicked = false
end
--local RandomNumber = math.random(1, #Magics)
ChosenMagic = Magics[math.random(1, #Magics)]
YourMagic.Text = ChosenMagic
local Number = math.random(1,2)
if Number == 2 then
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://6475635118"
Sound.Parent = workspace
Sound.PlaybackSpeed = 0.8
Sound.Volume = 0.5
Sound.MaxDistance = 10
Sound:Play()
else if Number == 1 then
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://6475619109"
Sound.Parent = workspace
Sound.PlaybackSpeed = 0.8
Sound.Volume = 0.5
Sound.MaxDistance = 10
Sound:Play()
end
end
wait(Amount)
LoopTimes.Value = LoopTimes.Value + 1
end
game.ReplicatedStorage.StringValues.ChosenMagic.Value = ChosenMagic
RS.RemoteEvents.GiveMagic:FireServer()
end)
Server script
game.ReplicatedStorage.RemoteEvents.TakeAwaySpins.OnServerEvent:Connect(function(player)
player.Backpack.Spins.Value = player.Backpack.Spins.Value - 1
end)
game.ReplicatedStorage.RemoteEvents.GiveMagic.OnServerEvent:Connect(function(Player)
local Backpack = Player.Backpack
local ChosenMagic = game.ReplicatedStorage.StringValues.ChosenMagic
local Magics = game.ReplicatedStorage.Magics
local GivenMagic = Magics[ChosenMagic.Value]:Clone()
GivenMagic.Parent = Backpack
end)

1 comment
I SOLVED IT!