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

Variable not changing in remote event?

Asked by 3 years ago

Sorry I didn't really know how to word the title I am not really that sure on what is going on but I made a script that when you mine a rock a certain amount of times it breaks and leaves an ore. When I move on to the next rock it still is using the old rocks int value rather than updating the the new rock. I tried resetting the variables back to nil when the original rock was broken but that didn't work either.

Client:

local Pickaxe = script.Parent
local Durability = script.Parent.Durability

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RemoteEvent = Pickaxe:WaitForChild("RemoteEvent")

local Debounce = true
local Delay = 1

function slash()
    local anim = Instance.new("StringValue")
    anim.Name = "toolanim"
    anim.Value = "Slash"
    anim.Parent = Pickaxe
end


Pickaxe.Activated:Connect(function()
    if Debounce then
        Debounce = false
        slash()

        if Mouse.Target.Name == "CoalRock1" or Mouse.Target.Name == "CoalRock2" or Mouse.Target.Name == "CoalRock3" then
            local rockhit = Mouse.Target
            local RockHealth = rockhit.RockHealth

            RemoteEvent:FireServer(rockhit, RockHealth, Durability, print("RemoteEventFired"))
        elseif Mouse.Target.Name == "BronzeRock1" or Mouse.Target.Name == "BronzeRock2" or Mouse.Target.Name == "BronzeRock3" then
            print("Pickaxe too low level")
        elseif Mouse.Target.Name == "GoldRock1" or Mouse.Target.Name == "GoldRock2" or Mouse.Target.Name == "GoldRock3" then
            print("Pickaxe too low level")
        else
            print("Error")
        end

        wait(Delay)
        Debounce = true
    end
end)

Server

local Pickaxe = script.Parent
local RemoteEvent = Pickaxe:WaitForChild("RemoteEvent")
local CoalOre = game.ReplicatedStorage.CoalOre

RemoteEvent.OnServerEvent:Connect(function(player, rockhit, Durability, RockHealth)
    print("RemoteEventRecieved")

    RockHealth.Value = RockHealth.Value - 1
    print("Rock Health is now: "  .. RockHealth.Value)

    --Durability.Value = Durability.Value - 1
    --print("Durability is now: "  .. Durability.Value)

    if RockHealth.Value <=0 then
        local Rock = rockhit
        local RockPos = Rock.CFrame
        local CoalOreCloan = CoalOre:Clone()
        CoalOreCloan.CFrame = RockPos
        CoalOreCloan.Name = "CoalOreCloan"
        CoalOreCloan.Parent = game.Workspace
        Rock:Destroy()
    end

    --if Durability.Value <=0 then
        --Pickaxe:Destroy()
    --end
end)

If anybody could help that would be really good! :)

0
your durability and rockhealth seem to be flipped, you fired (rockhit, RockHealth, Durability) and received (rockhit, Durability, RockHealth). so you're changing the durability. Speedmask 661 — 3y
0
Thank you that worked Equals_Sign 4 — 3y

Answer this question