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

No error, in the output. What's the diff between my script & "This Person" script?

Asked by 2 years ago
Edited 2 years ago

I tried my best to fix mine, and almost looks familiar with the person scripts. But, mines for whatever reason. The ice that I summoned from my screen we're vanished / gone into void. But, the person's script works perfectly...

Basically, what am I doing is. Whenever I press Z on the keyboard. There would be a summoned ice on the mouse player's targeted. The local script on StarterCharacterScripts are works perfectly fine

THE PERSON'S SCRIPT

local re = game.ReplicatedStorage:WaitForChild("IceMagicActivated")


local plrsCoolingDown = {}


local shard = script:WaitForChild("IceShard")


local ts = game:GetService("TweenService")

local ti = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)



re.OnServerEvent:Connect(function(plr, mouseCF)


    if plrsCoolingDown[plr] then return end

    plrsCoolingDown[plr] = true


    local start = CFrame.new(plr.Character.HumanoidRootPart.Position, mouseCF.Position)

    local goal = start.LookVector * 300


    local shardsNum = math.random(15, 30)

    local shardIncrements = 300 / shardsNum



    for i = 1, shardsNum do


        local newShard = shard:Clone()
        newShard.Anchored = true
        newShard.CanCollide = false


        local x, y, z = math.random(30, 50)/30 * i, math.random(30, 50)/30 * i * 2, math.random(30, 50)/30 * i

        newShard.Size = Vector3.new(0, 0, 0)

        newShard.Orientation = Vector3.new(math.random(-30, 30), math.random(-180, 180), math.random(-30, 30))


        local pos = plr.Character.HumanoidRootPart.Position + start.LookVector * (shardIncrements * i)

        newShard.Position = Vector3.new(pos.X, 0, pos.Z)


        local newSize = Vector3.new(x, y, z)
        local newPos = newShard.Position + Vector3.new(0, y/2.5, 0)

        local tween = ts:Create(newShard, ti, {Size = newSize, Position = newPos})


        newShard.Parent = workspace

        tween:Play()


        local charactersHit = {}

        newShard.Touched:Connect(function(touch)


            if touch.Parent:FindFirstChild("Humanoid") and touch.Parent ~= plr.Character and not charactersHit[touch.Parent] then

                charactersHit[touch.Parent] = true

                touch.Parent.Humanoid:TakeDamage(30)
            end
        end)


        coroutine.resume(coroutine.create(function()


            wait(3)


            local reverseTween = ts:Create(newShard, ti, {Size = Vector3.new(0, 0, 0), Position = Vector3.new(pos.X, 0, pos.Z)})

            reverseTween:Play()

            reverseTween.Completed:Wait()
            newShard:Destroy()
        end))


        wait(math.random(1, 100)/1000)
    end


    plrsCoolingDown[plr] = false
end)

MY VERISON

local re = game.ReplicatedStorage:WaitForChild("IceMagicActivated") -- Get the remote events

local plrsCoolingDown = {} -- List of player currently in cooldown.

local shard = script:WaitForChild("IceShard")

local ts = game:GetService("TweenService") -- Get tween service, allow us to animate objects

local ti = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut) -- First how long th eanimation last for, second argument style the animation start / end, Third is the position in the animation that the style occurs, which can be the start, end or both.

re.OnServerEvent:Connect(function(plr, mouseCF) -- The parameter mouseCF is the mouse.Hit value we send ourself. The parameter plr is the client sending this smsg

    if plrsCoolingDown[plr] then return end -- If the player still cooldown, then do nathing.

    plrsCoolingDown[plr] = true -- We insert the player into this list, telling the script that they are on cooldown as they have used the ice magic already.

    local start = CFrame.new(plr.Character.HumanoidRootPart.Position, mouseCF.Position) -- Make variable called start, which is the CFrame where the shards will start. We give the player's character's HumanoidRootPart's Position property for the position component and the position of the mouse's CFrame for the rotational component. This will make this CFrame face where is the mouse is going.

    local goal = start.LookVector * 300 -- We make a goal variable too, which make equal to the LookVector of the CFrame above multiplied by 70. The lookVector is the direction a CFrame is facing. By multiplying by 70 we go 70 studs foward in this direction. This means the range of the ice shard attack is 70 studs

    local shardsNum = math.random(15, 30) -- This will make random numbers, how many shards will be created.

    local shardIncrements = 300 / shardsNum -- Then, we divide our range by the number of shards to find out the distance between each shard.

    -- Local already good enough.

    for i = 1, shardsNum do --  This for loop will go through 1 to the number of shards we will create. This will allow u to make that amount of shards with minimal lines of code


        local newShard = shard:Clone() -- We make clone of the shard from this script.
        newShard.Anchored = true
        newShard.CanCollide = false

        local x, y, z = math.random(30, 50)/30 * i, math.random(30, 50)/30 * i * 2, math.random(30, 50)/30 * i -- Here we make random sizes of each axis We do this by getting between 30 & 50, dividing it by 30, then multiplying it by the iterator. This will create a sizze based on the shard number, so the shards get bigger further along

        newShard.Size = Vector3.new(0, 0, 0) -- We make it 0 size, since we want to animate it.

        newShard.Orientation = Vector3.new(math.random(-30, 30), math.random(-180, 180), math.random(-30, 30))




        local pos = plr.Character.HumanoidRootPart.Position * start.LookVector * (shardIncrements * i)

        newShard.Position = Vector3.new(pos.X, 0, pos.Z) -- Was wrong last time lmao

        -- Section 2

        local newSize = Vector3.new(x, y, z)

        -- We make a variable called newSize which is equal to values we made above for the size.
        local newPos = newShard.Position + Vector3.new(0, y/2.5, 0) -- We also make a variable called newPos, which is equal to the current position of the shard plus its y size divided by 2.5 on the Y axis which will put the shard above the ground.



        local tween = ts:Create(newShard, ti, {Size = newSize, Position = newPos}) -- Create function of the TweenService goals, this will create an animation that we can play. The object that will be animated is the first argument we give. The second is a tweeninfo defining how we want the animation to behave. The third argument is a dictionary containing the property names and their goal values. We give size & position and their new values, so size and position will be animated.

        newShard.Parent = workspace

        tween:Play()

        local charactersHit = {}

        newShard.Touched:Connect(function(touch)

            if touch.Parent:FindFirstChild("Humanoid") and touch.Parent ~= plr.Character and not charactersHit[touch.Parent] then

            charactersHit[touch.Parent] = true

            touch.Parent.Humanoid:TakeDamage(30)
            end
        end)

        coroutine.resume(coroutine.create(function()

            wait(3)

            local reverseTween = ts:Create(newShard, ti, {Size = Vector3.new(0, 0, 0), Position = Vector3.new(pos.X, 0, pos.Z)}) -- To make shard disappear, we willl use another tween, We do the same as before, but give differnt values for position and size.

            reverseTween:Play()

            reverseTween.Completed:Wait()
            newShard:Destroy()
        end))



        wait(math.random(1, 100)/1000) -- We pause the for loop for a random amount between 1 and 100, which we divided 1000 get a random pause between 0.001 and 0.1. This makes the shards appear gradually rather thann all at once.
    end


    plrsCoolingDown[plr] = false -- Lastly, when the loop is over, we remove the play from the plrsCooldownList, allowing them to use the ice magic again.
    print("Everything works, fine... or not bruh")
end)

Answer this question