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

How to check who was holding a ball tool after it was thrown?

Asked by 3 years ago

I have a script where it detects after the ball hits the ground, it resets everyone and puts the ball at a certain spot, the spot is infront of the team's spawn. But there's 2 different spawns on each sides of the map, Lets say Team 1 threw it and it hits the ground, I'd want the ball to spawn at Team 2's spawn and vice versa. I'm stumped, thanks for looking this over.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:findFirstChild("Football") 
    then print("Reset")
        for i, player in ipairs(game.Players:GetPlayers()) do
            if player.Character then
                local hum = player.Character:FindFirstChild('Humanoid')
                if hum then
                    wait(4)
                    hum.Health = 0
                    player:LoadCharacter()

                    local newItem = game.ReplicatedStorage.Football:Clone() 
                    newItem.Handle.CFrame = CFrame.new(-189.549, 1.55, -37.55) 
                    newItem.Parent = workspace
                end 
            end
        end
    end
end)

Thats the script so far, but I dont know how to detect who held it and what team they were on after it was thrown and hit the ground...

2 answers

Log in to vote
0
Answered by 3 years ago

you can make a string value and set the value to the player that has the ball before its thrown, easy, because tools are directly in the chaarcter when held so you can jsut do script.Parent.Parent and i think thats the character of the tool, so when the ball is thrown, just check that value and you can know what the name of the player who threw the ball was :)

then just do

game.Players[PlayerName.Value].Character

and that will give you the actuall character instead of just the name, so then you can do whatever you want with him/her.

hope this helps :3

0
How would I go about inputting that into a script? NortonHDD 21 — 3y
0
im not going to give it to you, if you want to learn, then study AlexanderYar 788 — 3y
0
you insert a string value into the script, and when the ball is cloned, also clone the stringvalue and put it into the ball, but set the value of it to the player's name before cloneing it, only two things, that simple, do it AlexanderYar 788 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I'm pretty sure this doesn't work but I'm trying lol. Hope it helps

Players = game:GetService("Players")
for i, player in pairs(Players:GetPlayers(player)) do
    local Tool = player.Backpack:FindFirstChild("ToolName")
    if Tool then
        -- insert your code here    
    end
end

Answer this question