So, I’m making a pushing simulator experience where if they push somebody they get points but how would I go by writing that script?
This is my current script:
local tool = script.Parent
local Player = tool.Parent.Parent
local leaderstats = Player.leaderstats.Pushs -- whatever the value in leaderstat is named
tool.Activated:Connect(function()
leaderstats.Value = leaderstats.Value + 1
end)
To ensure that there is a leaderstats folder, call WaitForChild()
local tool = script.Parent
local Player = tool.Parent.Parent
local leaderstats = Player:WaitForChild("leaderstats"):WaitForChild("Pushs") -- whatever the value in leaderstat is named
tool.Activated:Connect(function()
leaderstats.Value = leaderstats.Value + 1
end)
Of course this isn’t the only option, you can obtain the Player’s Character as well in order to get the Player Object (Which would probably be the better approach)
local tool = script.Parent
tool.Activated:Connect(function()
local Player = game.Players:GetPlayerFromCharacter(tool.Parent)
if Player then
local leaderstats = Player:WaitForChild("leaderstats"):WaitForChild("Pushs")
leaderstats.Value = leaderstats.Value + 1
end
end)
--localscript in tool
local Mouse = game.Players.LocalPlayer:GetMouse()
script.Parent.Activated:Connect(function()
script.Parent.RemoteEvent:FireServer(Mouse.Target)
end)
--serverscript in tool
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,target)
if target.Name == player.Name and target:IsA("Player") then
player.leaderstats.pushs.Value += 1
end
end)