Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make tool function Properly?

Asked by 5 years ago

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

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad

Answer this question