Hello! I’ve recently ran into a problem, I’m creating a Roblox sword fighting round based game. I’m currently making it so whenever a round starts you get a sword. I have a script inside of “StarterPack” that contains a local script with the following.
Whenever I run this script (Yes, the value is set to 1.) it doesn’t give me any errors but still runs the else statement printing “Error” in the output
local player = game:GetService("Players").LocalPlayer
local SwordModel = game.Lighting.Tools.ClassicSword
local SwordClone = SwordModel:Clone()
function GivePlayersTools()
if game.Workspace.StartGame.GivePlayersTools.Value == 1 then
SwordModel:Clone()
SwordClone.Parent = script.Parent
else
print("Error")
end
end
while wait() do
GivePlayersTools()
end
local val = workspace.StartGame
local classic_sword = game.Lighting.Tools.ClassicSword
local function Give_Swords()
for _, player in pairs(game.Players:GetPlayers()) do
classic_sword:Clone().Parent = player.Backpack
end
end
val:GetPropertyChangedSignal("Value"):Connect(function()
if val.Value == 1 then
Give_Swords()
end
end)
Store this as a server script. Each time the value is changed to 1, it’ll give a sword to every player in the server.
I’d also advise using either ReplicatedStorage or ServerStorage to store your swords, using Lighting as a storage model isn’t recommended and is deprecated since the new storage models were released for proper use.
With that, I’m assuming your original script would run on the client. I wouldn’t recommend that at all, because you’re creating swords locally so even if you equip those swords I don’t think any other client would see your character holding the swords; the server has to hand out the tools to the players directly for replication to take effect.
Hello, so I just got home. (when I posted this I wasn’t) and I tried the script but it didn’t work. I did everything you told me and I get this error.
14:28:14.757 - Workspace.ServerScript:10: attempt to index number with ‘GetPropertyChangedSignal’
(Script I used)
local val = workspace.StartGame.GivePlayersTools.Value
local classic_sword = game.Lighting.Tools.ClassicSword
local function Give_Swords()
for _, player in pairs(game.Players:GetPlayers()) do
classic_sword:Clone().Parent = player.Backpack
end
end
val:GetPropertyChangedSignal("Value"):Connect(function()
if val.Value == 1 then
Give_Swords()
end
end)```