I was making a tool, which I have done many times before but it keeps throwing out this error:
09:37:48.661 - Value is not a valid member of Model 09:37:48.662 - Stack Begin 09:37:48.662 - Script 'ServerScriptService.Saber', Line 3 09:37:48.662 - Stack End
I have checked multiple times but still can't find what the issue is.
Here is my local Script:
local debounce = false local Force = script.Parent:WaitForChild("Force") script.Parent.Equipped:Connect(function() local Player = game.Players.LocalPlayer local plr = game.Workspace:FindFirstChild(Player.Name) local Anim = script.Parent.Equip local Track = plr.Humanoid:LoadAnimation(Anim) Track:Play() script.Parent.Activated:Connect(function() if debounce then print("Anim Playing") else debounce = true --Play Animation-- local Player = game.Players.LocalPlayer local plr = game.Workspace:FindFirstChild(Player.Name) local Anim = script.Parent.Swing local Track = plr.Humanoid:LoadAnimation(Anim) Track:Play() game.ReplicatedStorage.Saber:FireServer(plr,Force) wait(0.7) debounce = false end end) end)
Here is my server Script:
game.ReplicatedStorage.Saber.OnServerEvent:Connect(function(plr,Force) local Player = game.Players:FindFirstChild(plr.Name) Player.leaderstats.Force.Value = Player.leaderstats.Force.Value + Force.Value end)
Thanks in advance
Change line 23 of your local script to:
game.ReplicatedStorage.Saber:FireServer(Force)
FireServer passes the player that fired the event as the first parameter to OnServerEvent, so you don't have to send it manually.
Also, you are already getting passed the player object in OnServerEvent, so you dont need line 2 in your server script. You can change it to something like this:
game.ReplicatedStorage.Saber.OnServerEvent:Connect(function(plr, Force) plr.leaderstats.Force.Value = plr.leaderstats.Force.Value + Force.Value end)
And for completeness, you shouldn't try to find the players character like you are on line 5 of the local script. When a tool is equipped it is parented to the players character - instead of line 5 you can just write:
local plr = tool.Parent
You might want to call it something like character though, as later you use plr to mean the player, which could get confusing.