So, I have a script that uses local player, and a touched function in it. It just flat out doesn't work. I know I can use remote events, but is there a different way to do it? Here's my code. Could there also be a way to access the player, from the character?
script.Parent.Touched:Connect(function(part2) local Player = game.Players:GetPlayerFromCharacter(part2.Parent) -- Checks and returns if the part associates to a player if Player then wait() print ("Touched") game.Players.LocalPlayer.Data.PistolAmmo.Value = game.Players.LocalPlayer.Data.PistolAmmo.Value + 5 end end)
script.Parent.Touched:Connect(function(part2) -- if something touches script.Parent, the function runs if game.Players:GetPlayerFromCharacter(part2.Parent) then -- if a player touched the part, this runs local Player = game.Players:GetPlayerFromCharacter(part2.Parent) -- takes player from character wait() -- waits print ("Touched") -- prints "Touched" into output Player.Data.PistolAmmo.Value = Player.Data.PistolAmmo.Value + 5 -- takes the Player.Data.PistoAmmo.Value and adds 5 to it end end)