Hi. Sorry for the confusing title, I didn’t really know how to word it.
I was wondering how to detect the person that shoots the ball into the part and then put their name into a text label.
For example, if someones username was bob and they scored, the text label would say “Bob scored!”
Here is a video example of what i want
video - YouTube
(when i score it shows my username on the screen)
Any help would be appreciated! Thanks.
Orbular3
(Orbular3)
November 24, 2021, 7:47pm
#2
When detecting the player who kicks the ball, you could store them in a value in the ball as something like “LastPlayerToTouch”. Then when a goal happens, you can get the player from the ball.
2 Likes
I would say use attributes
ball:SetAttribute("PlayerToKick", player.Name)
textLabel.Text = ball:GetAttribute("PlayerToKick")
1 Like
Orbular3
(Orbular3)
November 24, 2021, 7:52pm
#5
Could I see the script where you detect a player kicking the ball if possible?
1 Like
It is a tool with multiple scripts.
i have made it into a model, to make it easier: dev - Roblox
So would this go into a server sided script?
local ball = workspace.TPS
local player = game:GetService("Players")
ball:SetAttribute("PlayerToKick", player.Name)
Orbular3
(Orbular3)
November 24, 2021, 7:55pm
#8
How does the ball know to add velocity?
I believe it is because of the bodyforce/gyro
This isn’t the player variable but the variable of the players service.
This has to be runned every time the ball is kicked.
local ball = game.Workspace:WaitForChild("TPS")
ball.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
ball:SetAttribute("PlayerToKick", player.Name)
end)
then how would i use this script to display the players name when they score?
Orbular3
(Orbular3)
November 24, 2021, 7:58pm
#12
I mean where is the ball given velocity in the script
local Backspin = Instance.new("BodyAngularVelocity", hit)
Backspin.AngularVelocity = Player.Character["HumanoidRootPart"].CFrame.RightVector * 30
local curve = Instance.new("BodyThrust")
local F = Instance.new("BodyVelocity")
F.Velocity = (Player.Character["Right Leg"].CFrame.lookVector) * (power)
F.MaxForce = Vector3.new(15e+006, Angle * 2,15e+006)
AddPowers(hit, F, Backspin, .8, 2100, curve, (power))
I saw that when the you score something teleports you back to the middle you could use that script.
textLabel.Text = ball:GetAttribute("PlayerToKick").." scored."
sorry for the bad maths, im not that good at maths
Orbular3
(Orbular3)
November 24, 2021, 8:01pm
#16
Just before that, how does it know to give the ball velocity?
I have made this into a local script:
local textLabel = script.Parent:WaitForChild(“TextLabel”)
local ball = game.Workspace:WaitForChild(“TPS”)
textLabel.Text = ball:GetAttribute(“PlayerToKick”)…" scored."
I got an attempt index nil error.
I will look for that right now.
Yeah i cant seem to find anything about velocity above that script